Skip to content

Commit

Permalink
fix: avoid inconsitency between lastModified and postedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL committed Apr 12, 2024
1 parent be3818c commit 4e84769
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/handlers/handleWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 4e84769

Please sign in to comment.