Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(metadata): compatibility with old kv records #38

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/handlers/handleDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function handleDelete(request, env, ctx) {
if (item.value === null) {
throw new WorkerError(404, `paste of name '${short}' not found`)
} else {
if (passwd !== item.metadata.passwd) {
if (passwd !== item.metadata?.passwd) {
throw new WorkerError(403, `incorrect password for paste '${short}`)
} else {
await env.PB.delete(short)
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/handleRead.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function pasteCacheHeader(env) {
}

function lastModifiedHeader(paste) {
const lastModified = paste.metadata.lastModified
const lastModified = paste.metadata?.lastModified
return lastModified ? { "last-modified": new Date(lastModified).toGMTString() } : {}
}

Expand Down Expand Up @@ -53,7 +53,7 @@ export async function handleGet(request, env, ctx) {
}

// check `if-modified-since`
const pasteLastModified = item.metadata.lastModified
const pasteLastModified = item.metadata?.lastModified
const headerModifiedSince = request.headers.get("if-modified-since")
if (pasteLastModified && headerModifiedSince) {
let pasteLastModifiedMs = Date.parse(pasteLastModified)
Expand All @@ -68,7 +68,7 @@ export async function handleGet(request, env, ctx) {
}

// determine filename with priority: url path > meta
const returnFilename = filename || item.metadata.filename
const returnFilename = filename || item.metadata?.filename

// handle URL redirection
if (role === "u") {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/handleWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export async function handlePostOrPut(request, env, ctx, isPut) {
if (item.value === null) {
throw new WorkerError(404, `paste of name '${short}' is not found`)
} else {
const date = item.metadata.postedAt
if (passwd !== item.metadata.passwd) {
const date = item.metadata?.postedAt
if (passwd !== item.metadata?.passwd) {
throw new WorkerError(403, `incorrect password for paste '${short}`)
} else {
return makeResponse(
Expand Down
Loading