export type GetApiOpdsDownloadBookIdArgs = {book_id: string}; export type GetApiOpdsDownloadBookIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * OPDS download book * * GET /opds/download/{book_id} */ export const getApiOpdsDownloadBookId = async (args: GetApiOpdsDownloadBookIdArgs, options: GetApiOpdsDownloadBookIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") const url = `${baseUrl.replace(/\/+$/, '')}/opds/download/${encodeURIComponent(String(args.book_id))}${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() };