export type GetApiApiV1CamerasSnapOptions = {baseUrl: string, digestAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Return a captured image from the default camera * * GET /api/v1/cameras/snap */ export const getApiApiV1CamerasSnap = async (options: GetApiApiV1CamerasSnapOptions) => { 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/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() };