import { CaptchaResult, Setting } from "../types"; import { axios } from "./BaseAPI"; function getBaseURI(): string { const baseURL = axios.defaults.baseURL; if (!baseURL || baseURL === "undefined") { return ""; } return baseURL.replace(/\/$/, ""); } const getCaptchaAPI = () => `${getBaseURI()}/captcha`; async function captcha(width: number, height: number): Promise { return await axios.get(`/captcha?width=${width}&height=${height}`); } const getAttachmentReadAPI = (id: string) => `${getBaseURI()}/attach/read/${id}`; const getAttachmentTempReadAPI = (id: string) => `${getBaseURI()}/attach/temp/read?id=${id}`; async function settingMap(map: Record): Promise>> { const raw = await axios.post("/setting/map", map); const moduleMap = new Map>(); if (!raw || typeof raw !== "object") { return moduleMap; } for (const [module, settingRawMap] of Object.entries(raw as Record)) { if (!settingRawMap || typeof settingRawMap !== "object") { continue; } const settingMap = new Map(); for (const [key, setting] of Object.entries(settingRawMap as Record)) { settingMap.set(key, setting); } moduleMap.set(module, settingMap); } return moduleMap; } export default { getCaptchaAPI, captcha, getAttachmentReadAPI, getAttachmentTempReadAPI, settingMap };