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
64 changes: 30 additions & 34 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/src/pages/en/deep-dive/modules/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ The final part may be smaller than 5 MiB. On failure, active part uploads finish

### Batch Deletes

The S3 optimizer groups delete atoms into `DeleteObjects` requests with at most 1000 keys each. Requests contain XML and a `Content-MD5` header. The service result is handled per key: successful keys resolve, while keys reported in an S3 error result reject individually. If the whole batch request fails, every key in that batch fails.
The S3 optimizer groups delete atoms into `DeleteObjects` requests with at most 1000 keys each. Requests contain XML and a `Content-MD5` header. The service result is handled per key: successful keys resolve, while keys reported in an S3 error result reject individually. If the whole batch request fails, each key is retried with an individual `DELETE` request and handled independently.
Binary file modified harness.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"id": "s3",
"name": "S3",
"version": "0.1.7",
"version": "0.1.8",
"description": "S3 and S3-compatible backend support.",
"icon": "server",
"main": "https://sync.consensia.cc/modules/s3.js",
Expand Down
1 change: 0 additions & 1 deletion packages/s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
Binary,
RecordStore,
StoreOperations,
Stat,
RecordStat,
} from '@hesprs/sync-engine-sdk';
import type { App } from 'obsidian';
Expand Down
35 changes: 25 additions & 10 deletions packages/s3/src/s3/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from '@hesprs/sync-engine-sdk';
import { chunkSize, concurrency } from '@hesprs/sync-engine-sdk';
import { concatBinary, textToUint8Array } from '@repo/shared/binary';
import { getStatus } from '@repo/shared/error';
import { getMessage, getStatus } from '@repo/shared/error';
import normalizeEtag from '@repo/shared/normalize-etag';
import parseXML from '@repo/shared/parse-xml';
import { dirname, encodeUrl, isFolder } from '@repo/shared/path';
Expand Down Expand Up @@ -64,7 +64,7 @@ const sizeMissing = new Error('S3 did not return size for objects!');

function buildDeleteObjectsXml(keys: Array<string>): string {
const objects = keys.map((key) => `<Object><Key>${escapeXml(key)}</Key></Object>`).join('');
return `<?xml version="1.0" encoding="UTF-8"?><Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Quiet>true</Quiet>${objects}</Delete>`;
return `<Delete xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Quiet>true</Quiet>${objects}</Delete>`;
}

function escapeXml(str: string): string {
Expand Down Expand Up @@ -212,14 +212,29 @@ export default class S3Fs implements RootFs {
{ bucket: this.bucket, endpoint: this.endpoint, key: '/', urlStyle: this.urlStyle },
{ delete: '' },
);
const response = await this.requestOrThrow(url, {
body: textToUint8Array(body),
headers: {
'Content-MD5': await md5Base64(body),
'Content-Type': 'application/xml',
},
method: 'POST',
});
let response: RequestResponse;
try {
response = await this.requestOrThrow(url, {
body: textToUint8Array(body),
headers: {
'Content-MD5': await md5Base64(body),
'Content-Type': 'application/xml',
},
method: 'POST',
});
} catch {
await Promise.all(
batch.map(async (key) => {
try {
await this.delete(key);
result[key] = true;
} catch (error) {
result[key] = getMessage(error);
}
}),
);
continue;
}
Object.assign(result, parseBatchDeleteResponse(response.text(), batch));
}
return result;
Expand Down
Loading