Skip to content
Open
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: 4 additions & 6 deletions src/storage/version/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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, {
Expand All @@ -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();
Expand Down
68 changes: 65 additions & 3 deletions test/storage/version/put.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ describe('Version Put', () => {
contentType: 'text/html',
metadata: {
id: 'q123-456',
preparsingstore: Date.now(),
version: 'ver123',
},
status: 201,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -556,7 +554,6 @@ describe('Version Put', () => {
path: '/q',
timestamp: 123,
users: '[{"email":"anonymous"}]',
preparsingstore: 12345,
};
return { body: '', metadata, contentLength: 616 };
};
Expand Down Expand Up @@ -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: '<html><body>Old content</body></html>',
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: '<html><body>New content</body></html>',
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, '<html><body>Old content</body></html>');
assert.strictEqual(versionCommand.input.ContentLength, 36);
});

it('Test putVersion with JPEG binary content', async () => {
const sentCommands = [];
const mockS3Client = {
Expand Down