export type GetApiAvatarNameIdArgs = {name: string, id: string, width?: number | undefined, height?: number | undefined, method?: string | undefined}; export type GetApiAvatarNameIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Media thumbnail * * GET /avatar/{name}/{id} */ export const getApiAvatarNameId = async (args: GetApiAvatarNameIdArgs, options: GetApiAvatarNameIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/jpeg") if (args.width != null) query.append("width", String(args.width)) if (args.height != null) query.append("height", String(args.height)) if (args.method != null) query.append("method", String(args.method)) const url = `${baseUrl.replace(/\/+$/, '')}/avatar/${encodeURIComponent(String(args.name))}/${encodeURIComponent(String(args.id))}${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.blob() };