about summary refs log tree commit diff stats
path: root/classes/Handler/DownloadHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Handler/DownloadHandler.php')
-rw-r--r--classes/Handler/DownloadHandler.php38
1 files changed, 19 insertions, 19 deletions
diff --git a/classes/Handler/DownloadHandler.php b/classes/Handler/DownloadHandler.php
index 023ae8a..330c04f 100644
--- a/classes/Handler/DownloadHandler.php
+++ b/classes/Handler/DownloadHandler.php
@@ -11,26 +11,26 @@ use PDO;
 
 class DownloadHandler implements RequestHandlerInterface, AuthRequired
 {
-	public function handle(Request $request): Response
-	{
-		$bookid = (int) $request->getAttribute('id');
-		$caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB));
-		$sth = $caldb->prepare("SELECT path, name, format FROM data LEFT JOIN books ON (data.book = books.id) WHERE data.id = ?");
-		$sth->execute([$bookid]);
+    public function handle(Request $request): Response
+    {
+        $bookid = (int) $request->getAttribute('id');
+        $caldb = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB));
+        $sth = $caldb->prepare("SELECT path, name, format FROM data LEFT JOIN books ON (data.book = books.id) WHERE data.id = ?");
+        $sth->execute([$bookid]);
 
-		while ($row = $sth->fetch()) {
-			$filename = Config::get(Config::BOOKS_DIR) . "/" . $row["path"] . "/" . $row["name"] . "." . strtolower($row["format"]);
+        while ($row = $sth->fetch()) {
+            $filename = Config::get(Config::BOOKS_DIR) . "/" . $row["path"] . "/" . $row["name"] . "." . strtolower($row["format"]);
 
-			if (file_exists($filename)) {
-				return (new Response())
-					->withHeader("Content-type", mime_content_type($filename))
-					->withHeader("Content-Disposition", 'attachment; filename="' . basename($filename) . '"')
-					->withBody(file_get_contents($filename) ?: '');
-			}
-		}
+            if (file_exists($filename)) {
+                return (new Response())
+                    ->withHeader("Content-type", mime_content_type($filename))
+                    ->withHeader("Content-Disposition", 'attachment; filename="' . basename($filename) . '"')
+                    ->withBody(file_get_contents($filename) ?: '');
+            }
+        }
 
-		return (new Response())
-			->withStatus(404)
-			->withBody(json_encode(["error" => "Not found."]));
-	}
+        return (new Response())
+            ->withStatus(404)
+            ->withBody(json_encode(["error" => "Not found."]));
+    }
 }