function createRequestBody(
  queuedRequest,
) {
  const headers = {
    Authorization: rest.token,
    "User-Agent": USER_AGENT,
  };
  // GET METHODS SHOULD NOT HAVE A BODY
  if (queuedRequest.request.method.toUpperCase() === "GET") {
    queuedRequest.payload.body = undefined;
  }
  // IF A REASON IS PROVIDED ENCODE IT IN HEADERS
  if (queuedRequest.payload.body?.reason) {
    headers["X-Audit-Log-Reason"] = encodeURIComponent(
      queuedRequest.payload.body.reason,
    );
  }
  // IF A FILE/ATTACHMENT IS PRESENT WE NEED SPECIAL HANDLING
  if (queuedRequest.payload.body?.file) {
    if (!Array.isArray(queuedRequest.payload.body.file)) {
      queuedRequest.payload.body.file = [
        queuedRequest.payload.body.file,
      ];
    }
    const form = new FormData();
    for (let i = 0; i < queuedRequest.payload.body.file.length; i++) {
      form.append(
        `file${i}`,
        queuedRequest.payload.body.file[i].blob,
        queuedRequest.payload.body.file[i].name,
      );
    }
    form.append(
      "payload_json",
      JSON.stringify({
        ...queuedRequest.payload.body,
        file: undefined,
      }),
    );
    queuedRequest.payload.body.file = form;
  } else if (
    queuedRequest.payload.body && ![
      "GET",
      "DELETE",
    ].includes(queuedRequest.request.method)
  ) {
    headers["Content-Type"] = "application/json";
  }
  return {
    headers,
    body: queuedRequest.payload.body?.file ||
      JSON.stringify(queuedRequest.payload.body),
    method: queuedRequest.request.method.toUpperCase(),
  };
}
/** Creates the request body and headers that are necessary to send a request. Will handle different types of methods and everything necessary for discord. */
Creates the request body and headers that are necessary to send a request. Will handle different types of methods and everything necessary for discord.
Creates the request body and headers that are necessary to send a request . Will handle different types of methods and everything necessary for discord .
function createRequestBody(
  queuedRequest,
) {
  const headers = {
    Authorization: rest.token,
    "User-Agent": USER_AGENT,
  };
  if (queuedRequest.request.method.toUpperCase() === "GET") {
    queuedRequest.payload.body = undefined;
  }
  if (queuedRequest.payload.body?.reason) {
    headers["X-Audit-Log-Reason"] = encodeURIComponent(
      queuedRequest.payload.body.reason,
    );
  }
  if (queuedRequest.payload.body?.file) {
    if (!Array.isArray(queuedRequest.payload.body.file)) {
      queuedRequest.payload.body.file = [
        queuedRequest.payload.body.file,
      ];
    }
    const form = new FormData();
    for (let i = 0; i < queuedRequest.payload.body.file.length; i++) {
      form.append(
        `file${i}`,
        queuedRequest.payload.body.file[i].blob,
        queuedRequest.payload.body.file[i].name,
      );
    }
    form.append(
      "payload_json",
      JSON.stringify({
        ...queuedRequest.payload.body,
        file: undefined,
      }),
    );
    queuedRequest.payload.body.file = form;
  } else if (
    queuedRequest.payload.body && ![
      "GET",
      "DELETE",
    ].includes(queuedRequest.request.method)
  ) {
    headers["Content-Type"] = "application/json";
  }
  return {
    headers,
    body: queuedRequest.payload.body?.file ||
      JSON.stringify(queuedRequest.payload.body),
    method: queuedRequest.request.method.toUpperCase(),
  };
}
function createRequestBody ( queuedRequest , ) { const headers = { Authorization : rest . token , "User-Agent" : USER_AGENT , } ; if ( queuedRequest . request . method . toUpperCase ( ) === "GET" ) { queuedRequest . payload . body = undefined ; } if ( queuedRequest . payload . body ?. reason ) { headers [ "X-Audit-Log-Reason" ] = encodeURIComponent ( queuedRequest . payload . body . reason , ) ; } if ( queuedRequest . payload . body ?. file ) { if ( ! Array . isArray ( queuedRequest . payload . body . file ) ) { queuedRequest . payload . body . file = [ queuedRequest . payload . body . file , ] ; } const form = new FormData ( ) ; for ( let i = 0 ; i < queuedRequest . payload . body . file . length ; i ++ ) { form . append ( ` ${ i } ` , queuedRequest . payload . body . file [ i ] . blob , queuedRequest . payload . body . file [ i ] . name , ) ; } form . append ( "payload_json" , JSON . stringify ( { ... queuedRequest . payload . body , file : undefined , } ) , ) ; queuedRequest . payload . body . file = form ; } else if ( queuedRequest . payload . body && ! [ "GET" , "DELETE" , ] . includes ( queuedRequest . request . method ) ) { headers [ "Content-Type" ] = "application/json" ; } return { headers , body : queuedRequest . payload . body ?. file || JSON . stringify ( queuedRequest . payload . body ) , method : queuedRequest . request . method . toUpperCase ( ) , } ; }
Creates the request body and headers that are necessary to send a request.
Creates the request body and headers that are necessary to send a request .
// GET METHODS SHOULD NOT HAVE A BODY // IF A REASON IS PROVIDED ENCODE IT IN HEADERS // IF A FILE/ATTACHMENT IS PRESENT WE NEED SPECIAL HANDLING