From 4e84769437569266897f96b3f2c2e74bdd4a5c68 Mon Sep 17 00:00:00 2001 From: SharzyL Date: Fri, 12 Apr 2024 12:52:34 +0800 Subject: [PATCH] fix: avoid inconsitency between lastModified and postedAt --- src/handlers/handleWrite.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/handlers/handleWrite.js b/src/handlers/handleWrite.js index 5b9ea08..206e4ab 100644 --- a/src/handlers/handleWrite.js +++ b/src/handlers/handleWrite.js @@ -3,10 +3,12 @@ import { getBoundary, parseFormdata } from "../parseFormdata.js" import { decode, genRandStr, getDispFilename, params, parseExpiration, parsePath, WorkerError } from "../common.js" async function createPaste(env, content, isPrivate, expire, short, createDate, passwd, filename) { - createDate = createDate || new Date().toISOString() + const now = new Date().toISOString() + createDate = createDate || now passwd = passwd || genRandStr(params.ADMIN_PATH_LEN) const short_len = isPrivate ? params.PRIVATE_RAND_LEN : params.RAND_LEN + // repeat until finding an unused name if (short === undefined) { while (true) { short = genRandStr(short_len) @@ -20,7 +22,7 @@ async function createPaste(env, content, isPrivate, expire, short, createDate, p postedAt: createDate, passwd: passwd, filename: filename, - lastModified: new Date().toISOString(), + lastModified: now, }, }) let accessUrl = env.BASE_URL + "/" + short