diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-26 11:06:30 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-26 11:06:30 +0300 |
| commit | fa1bccd968647f6ab5cce0ec4293b39c6fde7633 (patch) | |
| tree | a51b489a43bdfcc2688bd0855cf3e32382ad958c /classes/Handler/CoverHandler.php | |
| parent | ab7702f0e3dd63bdeaea3cb6db138878774c3b47 (diff) | |
| download | the-epube-fa1bccd968647f6ab5cce0ec4293b39c6fde7633.tar.gz the-epube-fa1bccd968647f6ab5cce0ec4293b39c6fde7633.tar.xz | |
spaces to tabs
Diffstat (limited to 'classes/Handler/CoverHandler.php')
| -rw-r--r-- | classes/Handler/CoverHandler.php | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/classes/Handler/CoverHandler.php b/classes/Handler/CoverHandler.php index d219f84..d4c0a2c 100644 --- a/classes/Handler/CoverHandler.php +++ b/classes/Handler/CoverHandler.php @@ -11,32 +11,32 @@ use PDO; class CoverHandler implements RequestHandlerInterface, AuthRequired { - public function handle(Request $request): Response - { - $id = (int) $request->getAttribute('id'); - $db = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB)); - $sth = $db->prepare("SELECT has_cover, path FROM books WHERE id = ?"); - $sth->execute([$id]); + public function handle(Request $request): Response + { + $id = (int) $request->getAttribute('id'); + $db = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB)); + $sth = $db->prepare("SELECT has_cover, path FROM books WHERE id = ?"); + $sth->execute([$id]); - while ($line = $sth->fetch()) { - $filename = Config::get(Config::BOOKS_DIR) . "/" . $line["path"] . "/" . "cover.jpg"; + while ($line = $sth->fetch()) { + $filename = Config::get(Config::BOOKS_DIR) . "/" . $line["path"] . "/" . "cover.jpg"; - if (file_exists($filename)) { - return (new Response()) - ->withHeader("Content-type", mime_content_type($filename)) - ->withHeader('Cache-control', "max-age=" . STATIC_EXPIRES) - ->withHeader("Expires", gmdate("D, d M Y H:i:s \G\M\T", time()+STATIC_EXPIRES)) - ->withHeader("Last-Modified", gmdate("D, d M Y H:i:s \G\M\T", filemtime($filename))) - ->withBody(readfile($filename) ?: ''); - } else { - return (new Response()) - ->withStatus(404) - ->withBody("File not found."); - } - } + if (file_exists($filename)) { + return (new Response()) + ->withHeader("Content-type", mime_content_type($filename)) + ->withHeader('Cache-control', "max-age=" . STATIC_EXPIRES) + ->withHeader("Expires", gmdate("D, d M Y H:i:s \G\M\T", time()+STATIC_EXPIRES)) + ->withHeader("Last-Modified", gmdate("D, d M Y H:i:s \G\M\T", filemtime($filename))) + ->withBody(readfile($filename) ?: ''); + } else { + return (new Response()) + ->withStatus(404) + ->withBody("File not found."); + } + } - return (new Response()) - ->withStatus(404) - ->withBody("File not found."); - } + return (new Response()) + ->withStatus(404) + ->withBody("File not found."); + } } |
