export type GetApiLangArgs = {lang: string, force_reload?: boolean | undefined}; export type GetApiLangOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Index * * GET /{lang} */ export const getApiLang = async (args: GetApiLangArgs, options: GetApiLangOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") if (args.force_reload != null) query.append("force_reload", String(args.force_reload)) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.lang))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };