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 /classes/Handler | |
| 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 'classes/Handler')
| -rw-r--r-- | classes/Handler/GetinfoHandler.php | 38 | ||||
| -rw-r--r-- | classes/Handler/ListHandler.php | 13 |
2 files changed, 11 insertions, 40 deletions
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"] ?? "") ]; } |
