diff --git a/app.py b/app.py index 4b3fb5e..9f09a59 100644 --- a/app.py +++ b/app.py @@ -4,7 +4,7 @@ import threading import RNS from http.server import HTTPServer -from db import init_db, set_setting +from db import init_db, get_setting, set_setting from handlers import dispatch_request from gateway import GatewayState, GatewayHandler, GATEWAY_PORT diff --git a/handlers.py b/handlers.py index abd0d13..2f6f31f 100644 --- a/handlers.py +++ b/handlers.py @@ -116,6 +116,7 @@ def _error(status): PER_PAGE = 10 +BROWSE_PER_PAGE = 50 def _paginate(query, key="p"): @@ -126,10 +127,11 @@ def _paginate(query, key="p"): return max(1, page) -def _page_nav(page, total, base_url): - if total <= PER_PAGE: +def _page_nav(page, total, base_url, per_page=None): + per_page = per_page or PER_PAGE + if total <= per_page: return "" - total_pages = (total + PER_PAGE - 1) // PER_PAGE + total_pages = (total + per_page - 1) // per_page sep = "&" if "?" in base_url else "?" parts = [] if page > 1: @@ -377,13 +379,13 @@ def handle_add_submit(body): def handle_pages(query=None): page = _paginate(query or {}) - offset = (page - 1) * PER_PAGE + offset = (page - 1) * BROWSE_PER_PAGE db = get_db() try: total = db.execute("SELECT count(*) FROM pages").fetchone()[0] rows = db.execute( "SELECT id, url, title, note FROM pages ORDER BY id DESC LIMIT ? OFFSET ?", - (PER_PAGE, offset), + (BROWSE_PER_PAGE, offset), ).fetchall() items = "" for r in rows: @@ -404,7 +406,7 @@ def handle_pages(query=None): return _respond( f"
{total} page(s)
' f'