diff --git a/src/storage/version/put.js b/src/storage/version/put.js index 553b7f2..0d6bf29 100644 --- a/src/storage/version/put.js +++ b/src/storage/version/put.js @@ -179,10 +179,8 @@ export async function putObjectWithVersion( } } - const pps = current.metadata?.preparsingstore || '0'; - let storeBody = !body && pps === '0'; - let Preparsingstore = storeBody ? Timestamp : pps; - let Label = storeBody ? 'Collab Parse' : update.label; + let storeBody = false; + let Label = update.label; if (createVersion) { if (daCtx.method === 'PUT' @@ -196,7 +194,6 @@ export async function putObjectWithVersion( console.warn(`Empty body, creating a restore point (${current.contentLength} / ${update.body?.size})`); storeBody = true; Label = 'Restore Point'; - Preparsingstore = Timestamp; } const versionResp = await putVersion(config, { @@ -222,8 +219,9 @@ export async function putObjectWithVersion( } const metadata = { - ID, Users, Timestamp, Path, Preparsingstore, + ID, Users, Timestamp, Path, }; + // Only include Version metadata for files that support versioning if (createVersion) { metadata.Version = crypto.randomUUID(); diff --git a/test/storage/version/put.test.js b/test/storage/version/put.test.js index d6662a4..9d69354 100644 --- a/test/storage/version/put.test.js +++ b/test/storage/version/put.test.js @@ -300,7 +300,6 @@ describe('Version Put', () => { contentType: 'text/html', metadata: { id: 'q123-456', - preparsingstore: Date.now(), version: 'ver123', }, status: 201, @@ -363,7 +362,6 @@ describe('Version Put', () => { assert.equal('[{"email":"foo@acme.org"},{"email":"bar@acme.org"}]', s3Sent[0].input.Metadata.Users); assert.notEqual('aaa-bbb', s3Sent[0].input.Metadata.Version); assert(s3Sent[0].input.Metadata.Timestamp > 0); - assert((s3Sent[0].input.Metadata.Preparsingstore - s3Sent[0].input.Metadata.Timestamp) < 100); }); it('Put First Object With Version', async () => { @@ -556,7 +554,6 @@ describe('Version Put', () => { path: '/q', timestamp: 123, users: '[{"email":"anonymous"}]', - preparsingstore: 12345, }; return { body: '', metadata, contentLength: 616 }; }; @@ -886,6 +883,71 @@ describe('Version Put', () => { assert.strictEqual(putCommand.input.ContentLength, 9); }); + it('Test version stores body when body parameter is provided', async () => { + const sentCommands = []; + const mockS3Client = { + async send(cmd) { + sentCommands.push(cmd); + return { + $metadata: { httpStatusCode: 200 }, + }; + }, + }; + + const mockGetObject = async () => ({ + status: 200, + body: 'Old content', + contentLength: 36, + contentType: 'text/html', + etag: 'existing-etag', + metadata: { + id: 'doc-abc', + version: 'v4', + timestamp: '1234567890', + users: '[{"email":"user@example.com"}]', + path: 'docs/page4.html', + }, + }); + + const { putObjectWithVersion } = await esmock('../../../src/storage/version/put.js', { + '../../../src/storage/object/get.js': { + default: mockGetObject, + }, + '../../../src/storage/utils/version.js': { + ifMatch: () => mockS3Client, + ifNoneMatch: () => mockS3Client, + }, + }); + + const env = {}; + const daCtx = { + org: 'test-org', + bucket: 'test-bucket', + key: 'docs/page4.html', + ext: 'html', + method: 'PUT', + users: [{ email: 'user@example.com' }], + }; + + // Call WITH body parameter + await putObjectWithVersion(env, daCtx, { + bucket: 'test-bucket', + org: 'test-org', + key: 'docs/page4.html', + body: 'New content', + type: 'text/html', + }, true); // body parameter is true + + // Should have 2 commands: putVersion + putObject + assert.strictEqual(sentCommands.length, 2); + + // First command should be putVersion with the OLD body content + const versionCommand = sentCommands[0]; + assert.strictEqual(versionCommand.input.Key, 'test-org/.da-versions/doc-abc/v4.html'); + assert.strictEqual(versionCommand.input.Body, 'Old content'); + assert.strictEqual(versionCommand.input.ContentLength, 36); + }); + it('Test putVersion with JPEG binary content', async () => { const sentCommands = []; const mockS3Client = {