export type GetApiImgCoversBookCoverPathArgs = {book_cover_path: string}; export type GetApiImgCoversBookCoverPathOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get book cover image * * GET /img/covers/{book_cover_path} */ export const getApiImgCoversBookCoverPath = async (args: GetApiImgCoversBookCoverPathArgs, options: GetApiImgCoversBookCoverPathOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/jpeg") if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/img/covers/${encodeURIComponent(String(args.book_cover_path))}${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() };