Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store version content automatically once in preparation for parsing change #39

Merged
merged 10 commits into from
May 28, 2024
141 changes: 108 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint": "8.56.0",
"esmock": "^2.6.4",
"mocha": "^10.2.0",
"wrangler": "^3.17.1"
"wrangler": "^3.57.0"
},
"lint-staged": {
"*.js": "eslint",
Expand Down
2 changes: 1 addition & 1 deletion src/storage/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default async function putObject(env, daCtx, obj) {
const { body, type } = isFile ? await getFileBody(obj.data) : getObjectBody(obj.data);
status = await putObjectWithVersion(env, daCtx, {
org, key, body, type,
});
}, true);
}
} else {
const { body, type } = getObjectBody({});
Expand Down
13 changes: 11 additions & 2 deletions src/storage/version/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function putObjectWithVersion(env, daCtx, update, body) {
const input = buildInput(update);
const Timestamp = `${Date.now()}`;
const Path = update.key;

if (current.status === 404) {
const client = ifNoneMatch(config);
const command = new PutObjectCommand({
Expand All @@ -114,16 +115,24 @@ export async function putObjectWithVersion(env, daCtx, update, body) {
}
}

const pps = current.metadata?.preparsingstore || '0';

// Store the body if preparsingstore is not defined, so a once-off store
const storeBody = body && pps === '0';
const Preparsingstore = storeBody ? Timestamp : pps;
const Label = storeBody ? 'Collab Parse' : undefined;

const versionResp = await putVersion(config, {
Bucket: input.Bucket,
Body: current.body,
Body: (storeBody ? current.body : ''),
ID,
Version,
Ext: daCtx.ext,
Metadata: {
Users: current.metadata?.users || JSON.stringify([{ email: 'anonymous' }]),
Timestamp: current.metadata?.timestamp || Timestamp,
Path: current.metadata?.path || Path,
Label,
},
});

Expand All @@ -135,7 +144,7 @@ export async function putObjectWithVersion(env, daCtx, update, body) {
const command = new PutObjectCommand({
...input,
Metadata: {
ID, Version: crypto.randomUUID(), Users, Timestamp, Path,
ID, Version: crypto.randomUUID(), Users, Timestamp, Path, Preparsingstore,
},
});
try {
Expand Down
Loading
Loading