From c104601ab1d73688114befaced5b494f0a957e56 Mon Sep 17 00:00:00 2001 From: abersheeran Date: Sat, 6 Jan 2024 11:28:32 +0800 Subject: [PATCH] Refactor content headers and handle move operation --- src/index.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5ac48c8..2c5b89c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -138,28 +138,28 @@ async function handle_get(request: Request, bucket: R2Bucket): Promise ...(object.httpMetadata?.contentDisposition ? { - 'Content-Disposition': object.httpMetadata.contentDisposition, - } + 'Content-Disposition': object.httpMetadata.contentDisposition, + } : {}), ...(object.httpMetadata?.contentEncoding ? { - 'Content-Encoding': object.httpMetadata.contentEncoding, - } + 'Content-Encoding': object.httpMetadata.contentEncoding, + } : {}), ...(object.httpMetadata?.contentLanguage ? { - 'Content-Language': object.httpMetadata.contentLanguage, - } + 'Content-Language': object.httpMetadata.contentLanguage, + } : {}), ...(object.httpMetadata?.cacheControl ? { - 'Cache-Control': object.httpMetadata.cacheControl, - } + 'Cache-Control': object.httpMetadata.cacheControl, + } : {}), ...(object.httpMetadata?.cacheExpiry ? { - 'Cache-Expiry': object.httpMetadata.cacheExpiry.toISOString(), - } + 'Cache-Expiry': object.httpMetadata.cacheExpiry.toISOString(), + } : {}), }, }); @@ -292,9 +292,9 @@ function generate_propfind_response(object: R2Object | null): string { ${Object.entries(fromR2Object(object)) - .filter(([_, value]) => value !== undefined) - .map(([key, value]) => `<${key}>${value}`) - .join('\n ')} + .filter(([_, value]) => value !== undefined) + .map(([key, value]) => `<${key}>${value}`) + .join('\n ')} HTTP/1.1 200 OK @@ -496,7 +496,7 @@ async function handle_move(request: Request, bucket: R2Bucket): Promise { + const move = async (object: R2Object) => { let target = destination + '/' + object.key.slice(prefix.length); target = target.endsWith('/') ? target.slice(0, -1) : target; let src = await bucket.get(object.key); @@ -508,9 +508,9 @@ async function handle_move(request: Request, bucket: R2Bucket): Promise