about summary refs log tree commit diff stats
path: root/classes/Handler/LastreadHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/Handler/LastreadHandler.php')
-rw-r--r--classes/Handler/LastreadHandler.php128
1 files changed, 64 insertions, 64 deletions
diff --git a/classes/Handler/LastreadHandler.php b/classes/Handler/LastreadHandler.php
index cdaade0..ab177ed 100644
--- a/classes/Handler/LastreadHandler.php
+++ b/classes/Handler/LastreadHandler.php
@@ -10,76 +10,76 @@ use Response;
 
 class LastreadHandler implements RequestHandlerInterface, AuthRequired
 {
-	private function handleGet(int $bookid): Response
-	{
-		if ($bookid) {
-			$book = ORM::for_table('epube_books')
-				->where('bookid', $bookid)
-				->where('owner', $_SESSION["owner"] ?? "")
-				->find_one();
+    private function handleGet(int $bookid): Response
+    {
+        if ($bookid) {
+            $book = ORM::for_table('epube_books')
+                ->where('bookid', $bookid)
+                ->where('owner', $_SESSION["owner"] ?? "")
+                ->find_one();
 
-			if ($book) {
-				return (new Response())->withBody(json_encode([
-					"page" => (int)$book->lastread,
-					"cfi" => $book->lastcfi,
-					"total" => 100,
-					"timestamp" => (int)$book->lastts
-				]));
-			}
-		}
+            if ($book) {
+                return (new Response())->withBody(json_encode([
+                    "page" => (int)$book->lastread,
+                    "cfi" => $book->lastcfi,
+                    "total" => 100,
+                    "timestamp" => (int)$book->lastts
+                ]));
+            }
+        }
 
-		return (new Response())
-			->withStatus(404)
-			->withBody(json_encode(["error" => "Not found."]));
-	}
+        return (new Response())
+            ->withStatus(404)
+            ->withBody(json_encode(["error" => "Not found."]));
+    }
 
-	private function handleStore(int $bookid, int $page, string $cfi, int $timestamp): Response
-	{
-		if ($bookid) {
-			$book = ORM::for_table('epube_books')
-				->where('bookid', $bookid)
-				->where('owner', $_SESSION["owner"] ?? "")
-				->find_one();
+    private function handleStore(int $bookid, int $page, string $cfi, int $timestamp): Response
+    {
+        if ($bookid) {
+            $book = ORM::for_table('epube_books')
+                ->where('bookid', $bookid)
+                ->where('owner', $_SESSION["owner"] ?? "")
+                ->find_one();
 
-			if ($book) {
-				if (($timestamp >= $book->lastts) && ($page >= $book->lastread || $page == PAGE_RESET_PROGRESS)) {
-					$book->set([
-						'lastread' => $page,
-						'lastcfi' => $cfi,
-						'lastts' => $timestamp,
-					]);
-				}
-			} else {
-				$book = ORM::for_table('epube_books')->create();
-				$book->set([
-					'bookid' => $bookid,
-					'owner' => $_SESSION["owner"] ?? "",
-					'lastread' => $page,
-					'lastcfi' => $cfi,
-					'lastts' => $timestamp,
-				]);
-			}
+            if ($book) {
+                if (($timestamp >= $book->lastts) && ($page >= $book->lastread || $page == PAGE_RESET_PROGRESS)) {
+                    $book->set([
+                        'lastread' => $page,
+                        'lastcfi' => $cfi,
+                        'lastts' => $timestamp,
+                    ]);
+                }
+            } else {
+                $book = ORM::for_table('epube_books')->create();
+                $book->set([
+                    'bookid' => $bookid,
+                    'owner' => $_SESSION["owner"] ?? "",
+                    'lastread' => $page,
+                    'lastcfi' => $cfi,
+                    'lastts' => $timestamp,
+                ]);
+            }
 
-			$book->save();
-		}
+            $book->save();
+        }
 
-		return (new Response())->withBody(json_encode(["page" => $page, "cfi" => $cfi]));
-	}
+        return (new Response())->withBody(json_encode(["page" => $page, "cfi" => $cfi]));
+    }
 
-	public function handle(Request $request): Response
-	{
-		$subOp = $request->getAttribute('op', '');
-		$bookid = (int) $request->getAttribute('id');
+    public function handle(Request $request): Response
+    {
+        $subOp = $request->getAttribute('op', '');
+        $bookid = (int) $request->getAttribute('id');
 
-		return match ($subOp) {
-			'getlastread'    => $this->handleGet($bookid),
-			'storelastread'  => $this->handleStore(
-				$bookid,
-				(int) $request->getAttribute('page'),
-				(string) $request->getAttribute('cfi', ''),
-				(int) $request->getAttribute('timestamp'),
-			),
-			default          => (new Response())->withStatus(404)->withBody(json_encode(["error" => "Not found."])),
-		};
-	}
+        return match ($subOp) {
+            'getlastread'    => $this->handleGet($bookid),
+            'storelastread'  => $this->handleStore(
+                $bookid,
+                (int) $request->getAttribute('page'),
+                (string) $request->getAttribute('cfi', ''),
+                (int) $request->getAttribute('timestamp'),
+            ),
+            default          => (new Response())->withStatus(404)->withBody(json_encode(["error" => "Not found."])),
+        };
+    }
 }