fix(api): report writable the same way PUT decides, return backup path

- GET /api/projects now returns writable: canWrite(req) + token_required, so the
  backoffice no longer claims it can save when ADMIN_TOKEN is set (PUT answered 403)
- PUT response exposes database + backup (forward-slash relative paths), drop the
  dead payload.backup assignment
- fail fast with a Thai hint when the database cannot be opened (permissions or
  corrupt file) instead of an unhandled stack trace
- AGENTS.md: document the two response fields
This commit is contained in:
Bkk1234 committed 2026-11-23 00:33:30 +07:00
1 parent c2a2733172
commit 0fa0406770
4 files changed
+35 -9

No files matched your search

+3 -1
View File
@@ -513,7 +513,9 @@ export function adminView(ctx) {
textEl.textContent = "พร้อมเผยแพร่ผ่านเซิร์ฟเวอร์";
extraEl.textContent = apiState.writable
? "บันทึกลงฐานข้อมูล SQLite ได้ทันที"
: "อ่านได้ แต่เขียนไม่ได้ (ตรวจรหัสเผยแพร่)";
: apiState.tokenRequired
? "ต้องกรอกรหัสเผยแพร่ก่อนบันทึก"
: "อ่านได้ แต่เขียนไม่ได้";
hintEl.innerHTML =
"กด “เผยแพร่” แล้วข้อมูลจะถูกบันทึกลงฐานข้อมูล SQLite (<code>data/hobbypj.sqlite</code>) พร้อม export <code>data/projects.json</code> และ commit ขึ้น Git ให้อัตโนมัติ";
} else if (ctx.source === "cache") {