diff --git a/chat.sqlite3 b/chat.sqlite3 new file mode 100644 index 0000000..f316c42 Binary files /dev/null and b/chat.sqlite3 differ diff --git a/index.html b/index.html index 8f431b7..87b5ed3 100644 --- a/index.html +++ b/index.html @@ -965,8 +965,20 @@ if (oldest && oldest.id) url += `&before_id=${encodeURIComponent(oldest.id)}`; } const r = await fetch(url); - const data = await r.json().catch(() => ({})); - if (!r.ok || !data.ok) throw new Error(data.error || "chat load failed"); + const raw = await r.text().catch(() => ""); + let data = {}; + try { + data = raw ? JSON.parse(raw) : {}; + } catch { + data = {}; + } + if (!r.ok || !data.ok) { + const details = + (data && data.error) || + (raw && raw.trim() ? raw.trim().slice(0, 300) : "") || + `${r.status} ${r.statusText}`.trim(); + throw new Error(details || "chat load failed"); + } const pageDesc = data.items || []; const pageChrono = pageDesc.slice().reverse(); // newest->oldest => oldest->newest diff --git a/server.py b/server.py index 85ded77..ca01476 100644 --- a/server.py +++ b/server.py @@ -224,6 +224,8 @@ def _required_str(payload: Dict[str, Any], key: str) -> Tuple[Optional[str], Opt app = Flask(__name__, static_folder=".", static_url_path="") +# Accept both `/path` and `/path/` to be resilient behind proxies/CDNs. +app.url_map.strict_slashes = False def _db_connect() -> sqlite3.Connection: @@ -510,6 +512,7 @@ def discover_models(provider: str) -> list: @app.get("/api/chat") +@app.get("/api/chat/") def api_chat_list() -> Any: provider = request.args.get("provider", "").strip() if not provider: @@ -580,6 +583,7 @@ def api_chat_list() -> Any: @app.post("/api/chat/clear") +@app.post("/api/chat/clear/") def api_chat_clear() -> Any: payload = request.get_json(silent=True) or {} provider, err = _required_str(payload, "provider")