export type GetApiApiV1CamerasIdSnapOptions = {baseUrl: string, digestAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Return a captured image from the camera with a given id * * GET /api/v1/cameras/{id}/snap */ export const getApiApiV1CamerasIdSnap = async (options: GetApiApiV1CamerasIdSnapOptions) => { const {baseUrl, fetch: fetchFn = fetch, digestAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/png") if (digestAuth !== undefined) headers.set('authorization', `digest ${digestAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/cameras/${encodeURIComponent(String(args.id))}/snap${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() };