swc/bundler/tests/.cache/deno/6f040f7ce57e789f1697a18744f8af1ff6127f23.ts
강동윤 d60c3242af
fix(swc): Fix bugs (#1739)
swc_bundler:
 - Fix cycle detection for complex circular imports. (denoland/deno#10752)

swc_ecma_transforms_typescript:
 - Allow using large values for an enum variant.
2021-05-25 14:30:17 +09:00

37 lines
1.0 KiB
TypeScript

// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/rest/process_request.ts
import { BASE_URL } from "../util/constants.ts";
import { rest, RestPayload, RestRequest } from "./rest.ts";
/** Processes a request and assigns it to a queue or creates a queue if none exists for it. */
export async function processRequest(request: RestRequest, payload: RestPayload) {
const route = request.url.substring(request.url.indexOf("api/"));
const parts = route.split("/");
// REMOVE THE API
parts.shift();
// REMOVES THE VERSION NUMBER
if (parts[0]?.startsWith("v")) parts.shift();
// SET THE NEW REQUEST URL
request.url = `${BASE_URL}/v${rest.apiVersion}/${parts.join("/")}`;
// REMOVE THE MAJOR PARAM
parts.shift();
const [id] = parts;
const queue = rest.pathQueues.get(id);
// IF THE QUEUE EXISTS JUST ADD THIS TO THE QUEUE
if (queue) {
queue.push({ request, payload });
} else {
// CREATES A NEW QUEUE
rest.pathQueues.set(id, [
{
request,
payload,
},
]);
await rest.processQueue(id);
}
}