Skip to content

Commit a384662

Browse files
authored
fix: versioning timestamp for version and document itself (#144)
1 parent 2b3454b commit a384662

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/storage/version/put.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export async function putObjectWithVersion(env, daCtx, update, body, guid) {
120120
Ext: daCtx.ext,
121121
Metadata: {
122122
Users: current.metadata?.users || JSON.stringify([{ email: 'anonymous' }]),
123-
Timestamp: current.metadata?.timestamp || Timestamp,
123+
Timestamp,
124124
Path: current.metadata?.path || Path,
125125
Label,
126126
},
@@ -134,7 +134,12 @@ export async function putObjectWithVersion(env, daCtx, update, body, guid) {
134134
const command = new PutObjectCommand({
135135
...input,
136136
Metadata: {
137-
ID, Version: crypto.randomUUID(), Users, Timestamp, Path, Preparsingstore,
137+
ID,
138+
Version: crypto.randomUUID(),
139+
Users,
140+
Timestamp: current.metadata?.timestamp || Timestamp,
141+
Path,
142+
Preparsingstore,
138143
},
139144
});
140145
try {

test/storage/version/put.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe('Version Put', () => {
146146
metadata: {
147147
id: 'x123',
148148
version: 'aaa-bbb',
149+
timestamp: 1750765279755,
149150
},
150151
status: 200
151152
};
@@ -201,7 +202,7 @@ describe('Version Put', () => {
201202
assert.equal('x123', s3Sent[0].input.Metadata.ID);
202203
assert.equal('/a/x.html', s3Sent[0].input.Metadata.Path);
203204
assert.notEqual('aaa-bbb', s3Sent[0].input.Metadata.Version);
204-
assert(s3Sent[0].input.Metadata.Timestamp > 0);
205+
assert.strictEqual(1750765279755, s3Sent[0].input.Metadata.Timestamp);
205206
});
206207

207208
it('Put Object With Version don\'t store content', async () => {
@@ -498,8 +499,8 @@ describe('Version Put', () => {
498499
assert.equal('', input.Body, 'Empty body for HEAD');
499500
assert.equal(0, input.ContentLength, 'Should have used 0 as content length for HEAD');
500501
assert.equal('/q', input.Metadata.Path);
501-
assert.equal(123, input.Metadata.Timestamp);
502502
assert.equal('[{"email":"anonymous"}]', input.Metadata.Users);
503+
assert(input.Metadata.Timestamp > 0);
503504
});
504505

505506
it('Test putObjectWithVersion BODY', async () => {
@@ -563,8 +564,8 @@ describe('Version Put', () => {
563564
assert.equal('Somebody...', input.Body);
564565
assert.equal(616, input.ContentLength);
565566
assert.equal('/qwerty', input.Metadata.Path);
566-
assert.equal(1234, input.Metadata.Timestamp);
567567
assert.equal('[{"email":"anonymous"}]', input.Metadata.Users);
568+
assert(input.Metadata.Timestamp > 0);
568569

569570
assert.equal(1, sentToS3_2.length);
570571
const input2 = sentToS3_2[0].input;
@@ -574,6 +575,7 @@ describe('Version Put', () => {
574575
assert.equal('/mypath', input2.Key);
575576
assert.equal('/mypath', input2.Metadata.Path);
576577
assert.equal('[{"email":"hi@acme.com"}]', input2.Metadata.Users);
578+
assert.strictEqual(1234, input2.Metadata.Timestamp);
577579
assert(input2.Metadata.Version && input2.Metadata.Version !== 101);
578580
});
579581
});

0 commit comments

Comments
 (0)