Skip to content

Commit eb459b4

Browse files
committed
fix: add page_count column to store comic page counts for PSE
The page count was being calculated during scan but never stored in the database, causing PSE (Page Streaming Extension) to always report 0 pages in OPDS feeds. OPDS clients like Panels require page count > 0 to enable page streaming UI. Changes: - Add migration to add page_count column to items table - Update upsert_file() to accept and store page_count parameter - Update scan to pass calculated page_count to database - Update schema.sql to document the new column
1 parent 22ab507 commit eb459b4

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

app/db.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def _ensure_schema(conn: sqlite3.Connection) -> None:
8080
if not _column_exists(conn, "meta", "format"):
8181
_add_column(conn, "meta", "format", "TEXT")
8282

83+
# migration: ensure 'page_count' column exists in items table
84+
if not _column_exists(conn, "items", "page_count"):
85+
_add_column(conn, "items", "page_count", "INTEGER DEFAULT 0")
86+
8387
conn.execute("CREATE INDEX IF NOT EXISTS idx_items_parent ON items(parent)")
8488
conn.execute("CREATE INDEX IF NOT EXISTS idx_items_name ON items(name)")
8589
conn.execute("CREATE INDEX IF NOT EXISTS idx_items_isdir ON items(is_dir)")
@@ -192,21 +196,22 @@ def upsert_dir(conn: sqlite3.Connection, rel: str, name: str, parent: str, mtime
192196
(rel, name, parent, mtime),
193197
)
194198

195-
def upsert_file(conn: sqlite3.Connection, rel: str, name: str, size: int, mtime: float, parent: str, ext: str) -> None:
199+
def upsert_file(conn: sqlite3.Connection, rel: str, name: str, size: int, mtime: float, parent: str, ext: str, page_count: int = 0) -> None:
196200
"""Insert or update a file entry in the database."""
197201
conn.execute(
198202
"""
199-
INSERT INTO items(rel, name, parent, is_dir, size, mtime, ext)
200-
VALUES (?, ?, ?, 0, ?, ?, ?)
203+
INSERT INTO items(rel, name, parent, is_dir, size, mtime, ext, page_count)
204+
VALUES (?, ?, ?, 0, ?, ?, ?, ?)
201205
ON CONFLICT(rel) DO UPDATE SET
202206
name=excluded.name,
203207
parent=excluded.parent,
204208
is_dir=excluded.is_dir,
205209
size=excluded.size,
206210
mtime=excluded.mtime,
207-
ext=excluded.ext
211+
ext=excluded.ext,
212+
page_count=excluded.page_count
208213
""",
209-
(rel, name, parent, size, mtime, ext),
214+
(rel, name, parent, size, mtime, ext, page_count),
210215
)
211216

212217
def upsert_meta(conn: sqlite3.Connection, rel: str, meta: Dict[str, Any]) -> None:

app/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def _run_scan():
250250
mtime=mtime,
251251
parent=_parent_rel(rel),
252252
ext="cbz",
253+
page_count=page_count,
253254
)
254255
meta = _read_comicinfo(p)
255256
if meta:

app/schema.sql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
-- Items (dirs & files)
22
CREATE TABLE IF NOT EXISTS items (
3-
rel TEXT PRIMARY KEY,
4-
name TEXT,
5-
parent TEXT,
6-
is_dir INTEGER NOT NULL,
7-
size INTEGER,
8-
mtime REAL,
9-
ext TEXT
3+
rel TEXT PRIMARY KEY,
4+
name TEXT,
5+
parent TEXT,
6+
is_dir INTEGER NOT NULL,
7+
size INTEGER,
8+
mtime REAL,
9+
ext TEXT,
10+
page_count INTEGER DEFAULT 0
1011
);
1112
CREATE INDEX IF NOT EXISTS idx_items_parent ON items(parent);
1213
CREATE INDEX IF NOT EXISTS idx_items_name ON items(name);

0 commit comments

Comments
 (0)