export type GetApiFoodPhotoArgs = {food_name: string}; export type GetApiFoodPhotoOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Get pre-uploaded food image by food name * * GET /food/photo */ export const getApiFoodPhoto = async (args: GetApiFoodPhotoArgs, options: GetApiFoodPhotoOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.food_name != null) query.append("food_name", String(args.food_name)) const url = `${baseUrl.replace(/\/+$/, '')}/food/photo${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 undefined };