import config from "../config.json"; export async function batch( type: "public" | "internal", path: string, ids: string[], headers?: Record ): Promise { if (!config.api.enabled) { return "disabled" }; if (!headers) headers = {}; const res: Record = {}; for (const id of ids) { const info = await (await fetch(config.api.urls[type] + path + id, headers)).json(); res[id] = info; }; return res; }; export async function iterate( type: "public" | "internal", path: string, keys: { data: string, metadata: string } | null, startPage: number, endingPage?: number ): Promise { if (!config.api.enabled) { return "disabled" }; let res: Array = []; const firstPage: { [key: string]: any } = await (await fetch(config.api.urls[type] + path + 1)).json(); if (!keys) { keys = { data: "data", metadata: "meta" }; }; res.push(...firstPage[keys.data]); if (!endingPage) endingPage = firstPage[keys.metadata].lastPage; for (let index = startPage + 1; index < endingPage!; index++) { const page = await (await fetch(config.api.urls[type] + path + index)).json(); res.push(...page[keys.data]); }; return res; }; export async function batchAction(path: string, headers: Array>) { if (!config.api.enabled) { return "disabled" }; for (const request of headers) { fetch(config.api.urls.internal + path, request); }; };