export type CreateApiApiV1UAuthArgs = {'Api-Key': string, 'Api-Secret': string, body: {accessToken: string}}; export type CreateApiApiV1UAuthOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Đăng nhập bằng accesstoken * * POST /api/v1/u/auth */ export const createApiApiV1UAuth = async (args: CreateApiApiV1UAuthArgs, options?: CreateApiApiV1UAuthOptions) => { const {baseUrl = "http://baovothuat.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") headers.set('accept', "application/x-www-form-urlencoded;charset=utf-8;") if (args['Api-Key'] != null) headers.set("Api-Key", String(args['Api-Key'])) if (args['Api-Secret'] != null) headers.set("Api-Secret", String(args['Api-Secret'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/u/auth${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };