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

+5 -1
View File
@@ -202,7 +202,11 @@ export async function probePublishApi() {
const res = await fetch(API_URL, { method: "GET", cache: "no-store" });
if (!res.ok) return { available: false, status: res.status, message: `HTTP ${res.status}` };
const body = await res.json();
return { available: true, writable: Boolean(body?.writable) };
return {
available: true,
writable: Boolean(body?.writable),
tokenRequired: Boolean(body?.token_required),
};
} catch (error) {
return { available: false, status: 0, message: "เชื่อมต่อเซิร์ฟเวอร์ไม่ได้" };
}
+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") {