diff --git a/src/storage/object/get.js b/src/storage/object/get.js index cf17df94..04923694 100644 --- a/src/storage/object/get.js +++ b/src/storage/object/get.js @@ -36,7 +36,10 @@ export default async function getObject(env, { bucket, 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, { bucket, org, key }, head = false) status: resp.status, contentType: resp.headers.get('content-type'), contentLength: resp.headers.get('content-length'), - metadata: Metadata, + metadata: { + ...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/storage/object/get.test.js b/test/storage/object/get.test.js index 381f531c..ec3018b2 100644 --- a/test/storage/object/get.test.js +++ b/test/storage/object/get.test.js @@ -37,6 +37,7 @@ describe('Get Object', () => { const Body = Buffer.from('

hello world

'); const ContentType = 'text/html'; const ContentLength = Body.length; + const LastModified = new Date().toISOString const Metadata = { foo: 'bar' }; const ETag = 'etag123'; s3Mock @@ -49,6 +50,7 @@ describe('Get Object', () => { ContentType, ContentLength, Metadata, + LastModified, ETag, $metadata: { httpStatusCode: 200 }, }); @@ -56,7 +58,7 @@ describe('Get Object', () => { assert.strictEqual(resp.status, 200); assert.strictEqual(resp.contentType, ContentType); assert.strictEqual(resp.contentLength, ContentLength); - assert.deepStrictEqual(resp.metadata, Metadata); + assert.deepStrictEqual(resp.metadata, { ...Metadata, LastModified }); assert.strictEqual(resp.etag, ETag); assert.deepStrictEqual(resp.body, Body); }); @@ -75,6 +77,7 @@ describe('Get Object', () => { ); const savedFetch = globalThis.fetch; + const lastModified = new Date().toISOString(); try { globalThis.fetch = async (url, opts) => { called = true; @@ -87,6 +90,7 @@ describe('Get Object', () => { if (name === 'content-type') return 'text/html'; if (name === 'content-length') return '123'; if (name === 'etag') return 'etag456'; + if (name === 'last-modified') return lastModified; return null; }, forEach: (cb) => { @@ -100,7 +104,7 @@ describe('Get Object', () => { assert.strictEqual(resp.status, 200); assert.strictEqual(resp.contentType, 'text/html'); assert.strictEqual(resp.contentLength, '123'); - assert.deepStrictEqual(resp.metadata, { foo: 'bar' }); + assert.deepStrictEqual(resp.metadata, { foo: 'bar', LastModified: lastModified }); assert.strictEqual(resp.etag, 'etag456'); assert.strictEqual(resp.body, ''); assert(called, 'fetch should be called'); 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());