diff options
| author | fox <fox@fakecake.org> | 2026-10-26 20:10:04 +0300 |
|---|---|---|
| committer | GitLab <noreply@fakecake.org> | 2026-10-26 20:10:04 +0300 |
| commit | ea00a18082ab0144cb320434e25bc2c11d16e9a1 (patch) | |
| tree | c980eac83739b1b1c9bfae98c574d42983bdc927 | |
| parent | 094e1b8ce5f732fc3d789792ee36fc01cefbb734 (diff) | |
| parent | adfb195f806c9dfe05e9e21d846fd6d2b2573779 (diff) | |
| download | the-epube-master.tar.gz the-epube-master.tar.xz | |
* switch to different compose setup for dev without using See merge request git/the-epube!79
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 28 | ||||
| -rw-r--r-- | docker-compose.dev.yml | 24 | ||||
| -rw-r--r-- | docker-compose.yml | 2 | ||||
| -rw-r--r-- | offline.html | 3 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | src/app.ts | 58 |
7 files changed, 109 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore index 674c5f1..46b3d17 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /worker.js /.env /docker-compose.override.yml +/docker-compose.override.yaml /.app_is_ready /lib/epub.js/.git /db/*.db diff --git a/README.md b/README.md index 25e7190..cb40138 100644 --- a/README.md +++ b/README.md @@ -47,22 +47,34 @@ See `.env-dist` for configuration options. Development ----------- +Run the stack with the dev overlay, which bind-mounts the source tree into the +`app` and `web-nginx` containers and exposes PostgreSQL on `127.0.0.1:15432`: + + npm run dev # docker compose -f docker-compose.yml -f docker-compose.dev.yml + npm run dev -- up + npm run dev -- up -d app + npm run dev -- logs -f app + +The overlay is deliberately plain Compose (no `!override` YAML tag), so it works +with both Docker Compose and `podman-compose`, which only concatenates the volume +lists of the two files and keeps the last entry per mount target. + +Docker Compose v2.24+ users who prefer auto-loading may keep a local +`docker-compose.override.yml` instead, where the `!override` tag replaces volume +lists outright: + ```yaml services: - db: - ports: - - 127.0.0.1:15432:5432/tcp - app: volumes: !override - .:/var/www/html/books - ${BOOKS_DIR}:/books:ro - - web-nginx: - volumes: !override - - .:/var/www/html/books:ro ``` +Note that `podman-compose` cannot parse that tag and loads +`docker-compose.override.yml` automatically, so remove or rename the file if you +use `podman-compose` without explicit `-f` arguments. + License ------- diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..c1e9581 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,24 @@ +# Dev-only overlay, applied on top of docker-compose.yml: +# +# npm run dev # podman-compose -f docker-compose.yml -f docker-compose.dev.yml up +# +# It intentionally avoids the `!override` YAML tag (a Docker Compose v2.24+ +# extension) so that it also works with podman-compose, which concatenates the +# volume lists of both files and keeps the last entry per mount target. +services: + db: + ports: + # expose the database on the host for local tooling + - 127.0.0.1:15432:5432/tcp + + app: + volumes: + # live source checkout instead of the image copy + - .:/var/www/html/books + # re-declared so it wins over the base entry (last one per target wins) + - ${BOOKS_DIR}:/books:ro + + web-nginx: + volumes: + - .:/var/www/html/books:ro + - ${BOOKS_DIR}:/books:ro diff --git a/docker-compose.yml b/docker-compose.yml index 71f23c5..afd7262 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,8 @@ services: build: dockerfile: .docker/web-nginx/Dockerfile context: . + security_opt: + - apparmor=unconfined restart: unless-stopped env_file: - .env diff --git a/offline.html b/offline.html index ecbb01b..4728e13 100644 --- a/offline.html +++ b/offline.html @@ -67,6 +67,9 @@ </form> <ul class="nav navbar-nav navbar-right"> + <li><a href="#" class="remove_read_downloads" title="Remove finished downloads"> + <span class="glyphicon glyphicon-trash text-danger"></span> <span class='hidden-sm hidden-md hidden-lg'>Remove finished downloads</span> + </a></li> <li><a href="#" class="remove_all_downloads" title="Remove all downloads"> <span class="glyphicon glyphicon-remove-circle text-danger"></span> <span class='hidden-sm hidden-md hidden-lg'>Remove all downloads</span> </a></li> diff --git a/package.json b/package.json index 4276e2f..51c1366 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "scripts": { "build": "node build.js", "watch": "node build.js --watch", + "dev": "docker compose -f docker-compose.yml -f docker-compose.dev.yml", "eslint": "npx eslint src", "autoload": "composer dump-autoload --optimize", "phpstan": "./vendor/bin/phpstan --memory-limit=2G --error-format=raw analyze .", diff --git a/src/app.ts b/src/app.ts index 9da16c0..a446ea3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -254,6 +254,10 @@ class AppClass extends AppCommon { this.removeAll(); }); + $(".remove_read_downloads").on('click', () => { + this.removeRead(); + }); + $(".logout_link").on('click', () => { this.logout(); }); @@ -764,6 +768,60 @@ class AppClass extends AppCommon { } } + /** + * Remove downloaded books whose stored reading progress marks them as read + * (same heuristic as the rendered list: fewer than 5 pages left). + */ + async removeRead(): Promise<void> { + if (!confirm("Remove downloaded books marked as read?")) { + return; + } + + const suffixes = ["", ".book", ".cover", ".locations", ".lastread"]; + const promises: Promise<void>[] = []; + const keysToRemove: string[] = []; + + // Gather all individual asynchronous check operations + await localforage.iterate((value: unknown, key: string) => { + const match = key.match(/^epube-book\.(\d+)$/); + + if (!match) { + return; + } + + const cacheId = match[0]; + + // Push the pending getItem promise into our tracker array + const checkPromise = localforage.getItem(cacheId + ".lastread").then((raw) => { + if (!raw) { + return; + } + + const lastread = (typeof raw === "string" ? JSON.parse(raw) : raw) as LastRead; + const isRead = lastread.total > 0 && lastread.total - lastread.page < 5; + + if (isRead) { + console.log("offline remove read: " + cacheId); + for (const suffix of suffixes) { + keysToRemove.push(cacheId + suffix); + } + } + }); + + promises.push(checkPromise); + }); + + // Wait for ALL database lookups to completely finish evaluation + await Promise.all(promises); + + // Perform the actual removal of the compiled keys + if (keysToRemove.length > 0) { + await Promise.all(keysToRemove.map((key) => localforage.removeItem(key))); + } + + this.populateOfflineList(); + } + populateOfflineList(): void { let query = this.urlParam("query"); if (query) query = String(query).toLowerCase(); |
