From ec687731792891d7bbb7b31e27e31b0883608b3f Mon Sep 17 00:00:00 2001 From: wuyanwanwu <104009119+wuyanwanwu@users.noreply.github.com.> Date: Fri, 14 Aug 2026 23:15:24 +0800 Subject: [PATCH] Add China time to usage logs --- deploy/server.mjs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy/server.mjs b/deploy/server.mjs index 4e00bbd..69c1d69 100644 --- a/deploy/server.mjs +++ b/deploy/server.mjs @@ -10,6 +10,13 @@ const port = Number(process.env.APP_PORT || 3200); const dataDirectory = process.env.DATA_DIR || join(process.cwd(), "data"); const usageLogPath = join(dataDirectory, "usage.jsonl"); mkdirSync(dataDirectory, { recursive: true }); + +function formatChinaTimestamp(date) { + return new Date(date.getTime() + 8 * 60 * 60 * 1000) + .toISOString() + .replace("Z", "+08:00"); +} + const mimeTypes = { ".css": "text/css; charset=utf-8", ".html": "text/html; charset=utf-8", @@ -41,8 +48,10 @@ function writeUsageLog(request, response) { sendJson(response, 400, { error: "Invalid event" }); return; } + const now = new Date(); const entry = { - timestamp: new Date().toISOString(), + timestamp: now.toISOString(), + timestamp_cn: formatChinaTimestamp(now), event: input.event, client_hash: request.headers["x-forwarded-for"] || request.socket.remoteAddress ? createHash("sha256").update(String(request.headers["x-forwarded-for"] || request.socket.remoteAddress)).digest("hex").slice(0, 16)