Archived
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { apiClient, getApiBaseUrl } from "./client";
|
|
import type {
|
|
EBookListItem,
|
|
EBookDetail,
|
|
TocResponse,
|
|
PaginatedResponse,
|
|
} from "@cloud-reader/shared";
|
|
|
|
export const ebooksApi = {
|
|
/** List the authenticated user's uploaded e-books */
|
|
list() {
|
|
return apiClient.get<PaginatedResponse<EBookListItem>>(
|
|
"/api/books/ebooks/",
|
|
);
|
|
},
|
|
|
|
/** Get e-book detail (metadata, format, progress) */
|
|
get(id: number) {
|
|
return apiClient.get<EBookDetail>(`/api/books/ebooks/${id}/`);
|
|
},
|
|
|
|
/** Get the table of contents (used as a fallback for chapter navigation) */
|
|
getToc(id: number) {
|
|
return apiClient.get<TocResponse>(`/api/books/ebooks/${id}/toc/`);
|
|
},
|
|
|
|
/**
|
|
* Absolute URL to stream the raw ebook file. The endpoint requires JWT auth,
|
|
* so callers download it with an Authorization header (e.g. via
|
|
* expo-file-system) rather than handing the URL to a renderer directly.
|
|
*/
|
|
getFileUrl(id: number): string {
|
|
return `${getApiBaseUrl()}/api/books/ebooks/${id}/file/`;
|
|
},
|
|
};
|