diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-06-15 21:26:35 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-06-15 21:26:35 +0300 |
| commit | 23712d1e078fb065cd32f32b007da8f46619b55a (patch) | |
| tree | af48f672ca23e57d066f524ae614a09a61b0cf3b /src | |
| parent | 20c6c8f0bb3167852b5410afa64a017e62595835 (diff) | |
| download | the-epube-23712d1e078fb065cd32f32b007da8f46619b55a.tar.gz the-epube-23712d1e078fb065cd32f32b007da8f46619b55a.tar.xz | |
remove dedicated getinfo handler because list may operate on IDs; add some type definitions; bump request max body size for large pagination objects; always perform api requests network-first
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.js | 12 | ||||
| -rw-r--r-- | src/index.d.ts | 9 | ||||
| -rw-r--r-- | src/reader.js | 10 | ||||
| -rw-r--r-- | src/worker.js | 4 |
4 files changed, 28 insertions, 7 deletions
diff --git a/src/app.js b/src/app.js index 5cbf7ec..82a0013 100644 --- a/src/app.js +++ b/src/app.js @@ -232,7 +232,12 @@ class AppClass extends AppCommon { if (this.isOnline()) { - const data = await $.post("backend.php", {op: 'getinfo', id: bookId}); + /** @type{BookList} */ + const reply = await $.post("backend.php", {op: 'list', ids: bookId}); + + /** @type{BookInfo} */ + const data = reply['books'][0]; + const comment = data.comment ? data.comment : 'No description available'; $("#summary-modal .modal-title").text(data.title); @@ -383,7 +388,10 @@ class AppClass extends AppCommon { get(bookId, callback) { console.log("offline cache: " + bookId); - $.post("backend.php", {op: "getinfo", id: bookId}, (data) => { + $.post("backend.php", {op: "list", ids: bookId}, (/** @type{BookList} */ reply) => { + + /** @type{BookInfo} */ + const data = reply['books'][0]; if (data) { const cacheId = 'epube-book.' + bookId; diff --git a/src/index.d.ts b/src/index.d.ts index d7a8861..60ffba3 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -27,6 +27,15 @@ declare interface BookInfo { is_fav: boolean; epub_id: number; download_formats: DownloadFormat[]; + comment: string; + has_cover: boolean; +} + +declare interface BookList { + books: BookInfo[]; + total: number; + offset: number; + limit: number; } declare var EpubeApp: EpubeApp; diff --git a/src/reader.js b/src/reader.js index 7bcac76..0c61a0c 100644 --- a/src/reader.js +++ b/src/reader.js @@ -222,16 +222,20 @@ class ReaderClass extends AppCommon { console.log('requesting bookinfo for book', bookId) try { - const resp = await $.post("backend.php", {op: "getinfo", id: bookId }); + /** @type{BookList} */ + const resp = await $.post("backend.php", {op: "list", ids: bookId }); - if (resp.has_cover) { + /** @type{BookInfo} */ + const info = resp['books'][0]; + + if (info.has_cover) { const cover = await fetch("backend.php?op=cover&id=" + bookId); if (cover.ok) await localforage.setItem(this.cacheId('cover'), cover.blob()); } - await localforage.setItem(this.cacheId(), resp); + await localforage.setItem(this.cacheId(), info); console.log('bookinfo saved'); diff --git a/src/worker.js b/src/worker.js index 414c328..94da8db 100644 --- a/src/worker.js +++ b/src/worker.js @@ -80,8 +80,8 @@ sw.addEventListener('fetch', (event) => { // /assets/ belong to android app if (url.pathname.startsWith('/assets/')) return; - // request specific API endpoints from the network if possible and cache them locally - if (url.pathname.match('backend.php\\?op=(cover|getinfo)')) { + // request API endpoints from the network if possible and cache them locally + if (url.pathname.match('backend.php')) { event.respondWith( // @ts-ignore-next-line (async () => { |
