From fb3629520657f0c9096f0ba748f17359ef1e9869 Mon Sep 17 00:00:00 2001 From: Markus Haack Date: Mon, 30 Jun 2025 15:33:00 +0200 Subject: [PATCH] fix: last modified header for source --- src/storage/object/get.js | 10 ++++++++-- src/utils/daResp.js | 4 ++-- test/utils/daResp.test.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/storage/object/get.js b/src/storage/object/get.js index efb21604..4b4fbf13 100644 --- a/src/storage/object/get.js +++ b/src/storage/object/get.js @@ -36,7 +36,10 @@ export default async function getObject(env, { org, key }, head = false) { status: resp.$metadata.httpStatusCode, contentType: resp.ContentType, contentLength: resp.ContentLength, - metadata: resp.Metadata, + metadata: { + ...resp.Metadata, + LastModified: resp.LastModified, + }, etag: resp.ETag, }; } catch (e) { @@ -56,7 +59,10 @@ export default async function getObject(env, { org, key }, head = false) { status: resp.status, contentType: resp.headers.get('content-type'), contentLength: resp.headers.get('content-length'), - metadata: Metadata, + metadata: { + ...resp.Metadata, + LastModified: resp.headers.get('last-modified'), + }, etag: resp.headers.get('etag'), }; } diff --git a/src/utils/daResp.js b/src/utils/daResp.js index c52ac4fb..04f75b06 100644 --- a/src/utils/daResp.js +++ b/src/utils/daResp.js @@ -29,8 +29,8 @@ export default function daResp({ headers.append('X-da-id', metadata.id); } - if (metadata?.timestamp) { - headers.append('Last-Modified', new Date(parseInt(metadata.timestamp, 10)).toUTCString()); + if (metadata?.LastModified) { + headers.append('Last-Modified', new Date(metadata.LastModified).toUTCString()); } if (ctx?.aclCtx && status < 500) { diff --git a/test/utils/daResp.test.js b/test/utils/daResp.test.js index dde77221..16e2a083 100644 --- a/test/utils/daResp.test.js +++ b/test/utils/daResp.test.js @@ -19,7 +19,7 @@ describe('DA Resp', () => { const aclCtx = { actionSet: ['read', 'write'], pathLookup: new Map() }; const ctx = { key: 'foo/bar.html', aclCtx }; const body = 'foobar'; - const metadata = { id: '1234', timestamp: '1719235200000' }; + const metadata = { id: '1234', LastModified: '2024-06-24T13:20:00.000Z' }; const resp = daResp({status: 200, body, contentType: 'text/plain', contentLength: 777, metadata}, ctx); assert.strictEqual(body, await resp.text());