about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-15 15:02:49 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-15 15:02:49 +0300
commit5be2e526840b36ecbdb95ee4445e7b525af71ca9 (patch)
tree52645718b9db6adfdc56518c65825840b6f3d996 /src
parentf8ca5b587d15d03823eabf4601859b84a1238b3a (diff)
downloadthe-epube-5be2e526840b36ecbdb95ee4445e7b525af71ca9.tar.gz
the-epube-5be2e526840b36ecbdb95ee4445e7b525af71ca9.tar.xz
switch index.php to a static html page
Diffstat (limited to 'src')
-rw-r--r--src/app.js46
-rw-r--r--src/reader.js8
-rw-r--r--src/worker.js2
3 files changed, 43 insertions, 13 deletions
diff --git a/src/app.js b/src/app.js
index 095df1c..3734e11 100644
--- a/src/app.js
+++ b/src/app.js
@@ -33,10 +33,10 @@ class AppCommon {
     urlParam(name){
         try {
             const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
-            if (!results) return 0;
-            return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0;
+            if (!results) return "";
+            return decodeURIComponent(results[1].replace(/\+/g, " ")) || "";
         } catch (e) {
-            return 0;
+            return "";
         }
     }
 
@@ -133,6 +133,35 @@ class AppClass extends AppCommon {
     async init() {
         console.log('version', this.version, 'current, worker', await this.getActiveCacheVersion());
 
+        // Read URL params for mode/query/offset
+        this.index_mode = this.urlParam("mode") || "";
+        this.index_query = this.urlParam("query") || "";
+        const offsetParam = parseInt(this.urlParam("offset"));
+        this.index_offset = isNaN(offsetParam) ? 0 : offsetParam;
+
+        // Update navbar active states
+        if (this.index_mode === "favorites") {
+            $(".index_favorites").addClass("active");
+            $(".download_all_link").show();
+            $(".logout_link").hide();
+        } else {
+            $(".index_all").addClass("active");
+            $(".download_all_link").hide();
+        }
+
+        $(".search_query").val(this.index_query);
+
+        // Auth check: call backend with a minimal request; 401 means unauthorized
+        try {
+            const authParams = new URLSearchParams({op: "list", limit: "1"});
+            await $.get("backend.php?" + authParams.toString());
+            // If we get here without error, we're authenticated
+        } catch (e) {
+            // 401 Unauthorized — redirect to login
+            window.location.href = "login.php";
+            return;
+        }
+
         this.csrf_token = Cookie.get('epube_csrf_token');
 
         setupCsrfPrefilter(this.csrf_token);
@@ -143,7 +172,7 @@ class AppClass extends AppCommon {
             $(".separate-search").show();
             $("body").addClass("is-epube-app");
 
-            if (this.urlParam("mode") == "favorites")
+            if (this.index_mode == "favorites")
                 EpubeApp.setPage("PAGE_FAVORITES");
             else
                 EpubeApp.setPage("PAGE_LIBRARY");
@@ -348,10 +377,7 @@ class AppClass extends AppCommon {
         this.initNightMode();
         this.initCommonEventHandlers();
 
-        const query = this.urlParam("query");
-
-        if (query)
-            $(".search_query").val(query);
+        $(".search_query").val(this.urlParam("query"));
 
         this.populateOfflineList();
     }
@@ -578,6 +604,10 @@ class AppClass extends AppCommon {
             }
 
             this.updateIndexPagination(data);
+        }).fail((xhr) => {
+            if (xhr.status === 401) {
+                window.location.href = "login.php";
+            }
         });
     }
 
diff --git a/src/reader.js b/src/reader.js
index e1b2ab1..7bcac76 100644
--- a/src/reader.js
+++ b/src/reader.js
@@ -192,7 +192,7 @@ class ReaderClass extends AppCommon {
                 })
                 .fail(function(e) {
                     if (e && e.status == 401) {
-                        window.location.href = "index.php";
+                        window.location.href = "index.html";
                     }
                 });
         }
@@ -1310,13 +1310,13 @@ class ReaderClass extends AppCommon {
         if (this.isOnline()) {
             $.post("backend.php", { op: "storelastread", id: this.urlParam("id"), page: currentPage,
                 cfi: currentCfi, timestamp: lastread_timestamp }, () => {
-                window.location.href = this.urlParam("rt") ? "index.php?mode=" + this.urlParam("rt") : "index.php";
+                window.location.href = this.urlParam("rt") ? "index.html?mode=" + this.urlParam("rt") : "index.html";
             })
                 .fail(() => {
-                    window.location.href = "index.php";
+                    window.location.href = "index.html";
                 });
         } else {
-            window.location.href = "index.php";
+            window.location.href = "index.html";
         }
     }
 
diff --git a/src/worker.js b/src/worker.js
index af38aa4..414c328 100644
--- a/src/worker.js
+++ b/src/worker.js
@@ -105,7 +105,7 @@ sw.addEventListener('fetch', (event) => {
     }
 
     // index & read UI: online first; if offline, map index pages to offline.html & map all read.html?* to offline read.html
-    if (url.pathname == "/" || url.pathname.match("index.php|offline.html|read.html")) {
+    if (url.pathname == "/" || url.pathname.match("index.html|offline.html|read.html")) {
         event.respondWith(
             // @ts-ignore-next-line
             (async () => {