Add China time to usage logs
This commit is contained in:
+10
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user