export type CreateApiRecipeScanArgs = {test?: boolean | undefined, devicetype?: string | undefined, lat?: number | undefined, lng?: number | undefined}; export type CreateApiRecipeScanOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST an image as a new RecipeScan request * 1) Fetch the filename -- DONE * 2) Copy it to the pics/scan folder - ENSURE NO NAMING COLLISIONS -- DONE * 3) Create 120 thumbnail size in pics/scan/120 -- DONE * 4) Insert the CloudTasks record * 5) Create the HIT * 6) Update the CloudTasks record with the HIT ID * 7) Email the requesing user * 8) Call out to www.bigoven.com to fetch the image and re-create the thumbnail * * POST /recipe/scan */ export const createApiRecipeScan = async (args: CreateApiRecipeScanArgs, options?: CreateApiRecipeScanOptions) => { const {baseUrl = "https://api2.bigoven.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.test != null) query.append("test", String(args.test)) if (args.devicetype != null) query.append("devicetype", String(args.devicetype)) if (args.lat != null) query.append("lat", String(args.lat)) if (args.lng != null) query.append("lng", String(args.lng)) const url = `${baseUrl.replace(/\/+$/, '')}/recipe/scan${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };