This commit is contained in:
Patrick Alvin Alcala 2025-11-26 16:51:33 +08:00
parent fec3abd5d8
commit bcb83dfea5
13 changed files with 1542 additions and 4019 deletions

View file

@ -1,25 +1,46 @@
import { ofetch } from 'ofetch'
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
import * as fs from "node:fs";
import { ofetch } from "ofetch";
import * as toml from "toml";
const URL = $backendUrl.get()
const RETRY = $requestRetries.get()
const CODES = $requestRetryCodes.get()
const config = toml.parse(fs.readFileSync("configs/config.api.toml", "utf-8"));
const URL = config.backend.backend_url;
const RETRY = config.request.request_retries;
const CODES = config.request.request_retry_codes;
export default async (api: string, value?: any, value2?: any) => {
try {
let fetch
if (!value2) {
if (!value) {
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
} else {
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
}
} else {
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
}
const result = fetch
return [result, null]
} catch (error) {
return [[], error]
}
}
export default async (
api: string,
value?: string | number,
value2?: string | number,
) => {
try {
let fetch: { [key: string]: unknown };
if (!value2) {
if (!value) {
fetch = await ofetch(URL + api, {
parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
} else {
fetch = await ofetch(`${URL}${api}/${value}/fetch-data`, {
parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
}
} else {
fetch = await ofetch(`${URL}${api}/${value}/${value2}/fetch-data`, {
parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
}
const result = fetch;
return [result, null];
} catch (error) {
return [[], error];
}
};