diff --git a/frontend/index.client.js b/frontend/index.client.js
index f5f24ae..d9fcc85 100644
--- a/frontend/index.client.js
+++ b/frontend/index.client.js
@@ -68,7 +68,7 @@ window.addEventListener('DOMContentLoaded', () => {
let customName = '', adminUrl = '', file = null
const NAME_REGEX = /^[a-zA-Z0-9+_\-\[\]*$@,;]{3,}$/
- const EXPIRE_REGEX = /^\d+\s*[smhdwM]?$/
+ const EXPIRE_REGEX = /^\d+\s*[smhdwMY]?$/
const submitButton = $('#submit-button')
const deleteButton = $('#delete-button')
const pasteEditArea = $('#paste-textarea')
@@ -83,7 +83,10 @@ window.addEventListener('DOMContentLoaded', () => {
const pasteNotEmpty = inputType === 'edit'
? pasteEditArea.prop('value').length > 0
: file !== null
- const expirationValid = EXPIRE_REGEX.test(expiration) // TODO: verify it
+ expirationValid = EXPIRE_REGEX.test(expiration) // TODO: verify it
+ if (!expiration) {
+ expirationValid = true
+ }
const nameValid = urlType !== 'custom' || NAME_REGEX.test(customName)
const adminUrlValid = urlType !== 'admin' || isAdminUrlLegal(adminUrl)
diff --git a/frontend/index.html b/frontend/index.html
index 15ab1e5..01d38c3 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -43,7 +43,7 @@
Settings
-
+
diff --git a/src/common.js b/src/common.js
index 9f00ff9..6808348 100644
--- a/src/common.js
+++ b/src/common.js
@@ -75,7 +75,10 @@ export function parsePath(pathname) {
}
export function parseExpiration(expirationStr) {
- const EXPIRE_REGEX = /^[\d\.]+\s*[smhdwM]?$/
+ if (!expirationStr) {
+ return NaN
+ }
+ const EXPIRE_REGEX = /^[\d\.]+\s*[smhdwMY]?$/
if (!EXPIRE_REGEX.test(expirationStr)) {
throw new WorkerError(400, `‘${expirationStr}’ is not a valid expiration specification`)
}
@@ -86,7 +89,8 @@ export function parseExpiration(expirationStr) {
else if (lastChar === 'h') expirationSeconds *= 3600
else if (lastChar === 'd') expirationSeconds *= 3600 * 24
else if (lastChar === 'w') expirationSeconds *= 3600 * 24 * 7
- else if (lastChar === 'M') expirationSeconds *= 3600 * 24 * 7 * 30
+ else if (lastChar === 'M') expirationSeconds *= 3600 * 24 * 30
+ else if (lastChar === 'Y') expirationSeconds *= 3600 * 24 * 365
return expirationSeconds
}
diff --git a/src/handlers/handleWrite.js b/src/handlers/handleWrite.js
index c5138c6..0401064 100644
--- a/src/handlers/handleWrite.js
+++ b/src/handlers/handleWrite.js
@@ -25,15 +25,21 @@ async function createPaste(env, content, isPrivate, expire, short, createDate, p
}
}
- await env.PB.put(short, content, {
- expirationTtl: expire,
+ let options = {
metadata: {
postedAt: createDate,
passwd: passwd,
filename: filename,
lastModified: now,
},
- })
+ }
+
+ if (!isNan(expire)) {
+ options.expirationTtl = expire
+ }
+
+ await env.PB.put(short, content, options)
+
let accessUrl = env.BASE_URL + "/" + short
const adminUrl = env.BASE_URL + "/" + short + params.SEP + passwd
return {
@@ -101,10 +107,7 @@ export async function handlePostOrPut(request, env, ctx, isPut) {
let expirationSeconds = undefined
if (expire !== undefined) {
expirationSeconds = parseExpiration(expire)
- if (isNaN(expirationSeconds)) {
- throw new WorkerError(400, `cannot parse expire ${expirationSeconds} as an number`)
- }
- if (expirationSeconds < 60) {
+ if (!isNan(expirationSeconds) && expirationSeconds < 60) {
throw new WorkerError(
400,
`due to limitation of Cloudflare, expire should be a integer greater than 60, '${expirationSeconds}' given`,