fix: 页面时间戳统一存UTC(Z), 前端按访问者本地时区显示, 修正容器时区导致的8小时偏差

This commit is contained in:
ylhan
2026-09-22 00:18:37 +08:00
parent 3733045341
commit e7ddce06ea
+5 -3
View File
@@ -204,7 +204,9 @@ const state={pages:[], mode:'list', current:null, content:''};
const umarked = typeof marked==='undefined'; const umarked = typeof marked==='undefined';
function toast(msg){const t=$('#toast');t.textContent=msg;t.classList.add('show');clearTimeout(t._h);t._h=setTimeout(()=>t.classList.remove('show'),1800);} function toast(msg){const t=$('#toast');t.textContent=msg;t.classList.add('show');clearTimeout(t._h);t._h=setTimeout(()=>t.classList.remove('show'),1800);}
function fmt(ts){ if(!ts)return ''; try{return new Date(ts).toLocaleString('zh-CN');}catch(e){return ts;} } function fmt(ts){ if(!ts)return ''; const s=String(ts);
const iso=(/Z$/i.test(s)||/([+-]\d{2}:\d{2})$/.test(s))?s:s+'Z';
try{return new Date(iso).toLocaleString('zh-CN');}catch(e){return ts;} }
async function loadPages(){ async function loadPages(){
state.pages = await api('/api/pages'); state.pages = await api('/api/pages');
@@ -532,7 +534,7 @@ class Handler(BaseHTTPRequestHandler):
with _lock: with _lock:
pages = _read_pages() pages = _read_pages()
pid = uuid.uuid4().hex[:12] pid = uuid.uuid4().hex[:12]
now = time.strftime("%Y-%m-%dT%H:%M:%S") now = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
pages[pid] = {"title": data["title"].strip(), pages[pid] = {"title": data["title"].strip(),
"content": data.get("content", ""), "content": data.get("content", ""),
"created": now, "updated": now} "created": now, "updated": now}
@@ -551,7 +553,7 @@ class Handler(BaseHTTPRequestHandler):
pages[pid]["title"] = data["title"].strip() pages[pid]["title"] = data["title"].strip()
if "content" in data: if "content" in data:
pages[pid]["content"] = data["content"] or "" pages[pid]["content"] = data["content"] or ""
pages[pid]["updated"] = time.strftime("%Y-%m-%dT%H:%M:%S") pages[pid]["updated"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
_write_pages(pages) _write_pages(pages)
self._json({"id": pid}) self._json({"id": pid})