Skip to content
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
10 changes: 8 additions & 2 deletions src/storage/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'),
};
}
4 changes: 2 additions & 2 deletions src/utils/daResp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions test/storage/object/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Get Object', () => {
const Body = Buffer.from('<p>hello world</p>');
const ContentType = 'text/html';
const ContentLength = Body.length;
const LastModified = new Date().toISOString
const Metadata = { foo: 'bar' };
const ETag = 'etag123';
s3Mock
Expand All @@ -49,14 +50,15 @@ describe('Get Object', () => {
ContentType,
ContentLength,
Metadata,
LastModified,
ETag,
$metadata: { httpStatusCode: 200 },
});
const resp = await getObject({}, { bucket: BUCKET, org: ORG, key: KEY }, false);
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);
});
Expand All @@ -75,6 +77,7 @@ describe('Get Object', () => {
);

const savedFetch = globalThis.fetch;
const lastModified = new Date().toISOString();
try {
globalThis.fetch = async (url, opts) => {
called = true;
Expand All @@ -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) => {
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion test/utils/daResp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading