about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-15 21:26:35 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-15 21:26:35 +0300
commit23712d1e078fb065cd32f32b007da8f46619b55a (patch)
treeaf48f672ca23e57d066f524ae614a09a61b0cf3b
parent20c6c8f0bb3167852b5410afa64a017e62595835 (diff)
downloadthe-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
-rw-r--r--.docker/web-nginx/nginx.conf3
-rw-r--r--backend.php1
-rw-r--r--classes/Handler/GetinfoHandler.php38
-rw-r--r--classes/Handler/ListHandler.php13
-rw-r--r--src/app.js12
-rw-r--r--src/index.d.ts9
-rw-r--r--src/reader.js10
-rw-r--r--src/worker.js4
8 files changed, 42 insertions, 48 deletions
diff --git a/.docker/web-nginx/nginx.conf b/.docker/web-nginx/nginx.conf
index 8ee0d91..8fb8ce2 100644
--- a/.docker/web-nginx/nginx.conf
+++ b/.docker/web-nginx/nginx.conf
@@ -39,6 +39,9 @@ http {
 			return 301 $base_path/index.html;
 		}
 
+		# pagination may be quite large
+		client_max_body_size 0;
+
 		location ~ \.php$ {
 			# regex to split $uri to $fastcgi_script_name and $fastcgi_path
 			fastcgi_split_path_info ^(.+?\.php)(/.*)$;
diff --git a/backend.php b/backend.php
index 135943c..028f4d1 100644
--- a/backend.php
+++ b/backend.php
@@ -17,7 +17,6 @@
 	$router->addRoute("oidc-login-callback", new \Handler\LoginHandler());
 	$router->addRoute("healthz", new \Handler\HealthzHandler());
 	$router->addRoute("cover", new \Handler\CoverHandler());
-	$router->addRoute("getinfo", new \Handler\GetinfoHandler());
 	$router->addRoute("list", new \Handler\ListHandler());
 	$router->addRoute("togglefav", new \Handler\TogglefavHandler());
 	$router->addRoute("download", new \Handler\DownloadHandler());
diff --git a/classes/Handler/GetinfoHandler.php b/classes/Handler/GetinfoHandler.php
deleted file mode 100644
index ee4a69a..0000000
--- a/classes/Handler/GetinfoHandler.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-namespace Handler;
-
-use AuthRequired;
-use Config;
-use Request;
-use RequestHandlerInterface;
-use Response;
-use PDO;
-use Sanitizer;
-
-class GetinfoHandler implements RequestHandlerInterface, AuthRequired
-{
-    public function handle(Request $request): Response
-    {
-        $id = (int) $request->getAttribute('id');
-        $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB));
-
-        $sth = $caldb->prepare("SELECT books.*, s.name AS series_name,
-            (SELECT text FROM comments WHERE book = books.id) AS comment,
-            (SELECT id FROM data WHERE book = books.id AND format = 'EPUB' LIMIT 1) AS epub_id FROM books
-            LEFT JOIN books_series_link AS bsl ON (bsl.book = books.id)
-            LEFT JOIN series AS s ON (bsl.series = s.id)
-            WHERE books.id = ?");
-        $sth->execute([$id]);
-
-        if ($row = $sth->fetch()) {
-            $row['comment'] = Sanitizer::sanitize($row['comment'] ?? "");
-
-            return (new Response())->withBody(json_encode($row));
-        }
-
-        return (new Response())
-            ->withStatus(404)
-            ->withBody(json_encode(["error" => "Not found."]));
-    }
-}
diff --git a/classes/Handler/ListHandler.php b/classes/Handler/ListHandler.php
index 9c65176..6628cee 100644
--- a/classes/Handler/ListHandler.php
+++ b/classes/Handler/ListHandler.php
@@ -22,7 +22,9 @@ class ListHandler implements RequestHandlerInterface, AuthRequired
         $ldb = \Db::pdo();
         $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB));
 
-        $ids_qpart = "1";
+        $ids = array_filter(
+            explode(",", $request->getAttribute('ids', '')), 'intval');
+
 
         if ($mode == "favorites") {
             $fav_sth = $ldb->prepare("SELECT bookid FROM epube_favorites WHERE owner = ?");
@@ -38,14 +40,19 @@ class ListHandler implements RequestHandlerInterface, AuthRequired
             }
 
             $ids_qpart = "books.id IN (" . implode(",", $fav_ids) . ")";
+        } else if (count($ids) > 0) {
+            $ids_qpart = "books.id IN (" . implode(",", $ids) . ")";
+        } else {
+            $ids_qpart = "1";
         }
 
         $order_by = $query ? "author_sort, series_name, series_index, title, books.id" : "books.id DESC";
 
-        $sth = $caldb->prepare("SELECT books.*, s.name AS series_name,
+        $sth = $caldb->prepare("SELECT books.*, s.name AS series_name, c.text AS comment,
             (SELECT id FROM data WHERE book = books.id AND format = 'EPUB' LIMIT 1) AS epub_id FROM books
             LEFT JOIN books_series_link AS bsl ON (bsl.book = books.id)
             LEFT JOIN series AS s ON (bsl.series = s.id)
+            LEFT JOIN comments AS c ON (c.book = books.id)
             WHERE
                 ((:query = '') OR
                     (
@@ -117,11 +124,13 @@ class ListHandler implements RequestHandlerInterface, AuthRequired
                 "series_name" => $line["series_name"] ?? "",
                 "series_index" => $line["series_index"] ?? 0,
                 "cover_link" => $cover_link,
+                "has_cover" => $line["has_cover"] == 1,
                 "in_progress" => $in_progress,
                 "is_read" => $is_read,
                 "is_fav" => $is_fav,
                 "epub_id" => $line["epub_id"] ?? 0,
                 "download_formats" => $download_formats,
+                "comment" => \Sanitizer::sanitize($line["comment"] ?? "")
             ];
         }
 
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 () => {