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