feat: optimize attachment handling in backup process

This commit is contained in:
shuaiplus
2026-04-18 03:55:27 +08:00
parent 08414d7cf2
commit dabd2c923e
+20 -18
View File
@@ -218,26 +218,28 @@ async function executeConfiguredBackup(
: 'txt_backup_remote_run_progress_sync_attachments_skipped_detail', : 'txt_backup_remote_run_progress_sync_attachments_skipped_detail',
}); });
const remoteSession = createRemoteBackupTransferSession(destination); const remoteSession = createRemoteBackupTransferSession(destination);
const remoteAttachmentIndex = await loadRemoteAttachmentIndex(remoteSession); if (destination.includeAttachments) {
let attachmentIndexChanged = false; const remoteAttachmentIndex = await loadRemoteAttachmentIndex(remoteSession);
for (const attachment of archive.manifest.attachmentBlobs || []) { let attachmentIndexChanged = false;
if (remoteAttachmentIndex.get(attachment.blobName) === attachment.sizeBytes) { for (const attachment of archive.manifest.attachmentBlobs || []) {
continue; if (remoteAttachmentIndex.get(attachment.blobName) === attachment.sizeBytes) {
continue;
}
const remotePath = `attachments/${attachment.blobName}`;
const object = await getBlobObject(env, attachment.blobName);
if (!object) {
throw new Error(`Attachment blob missing for ${attachment.blobName}`);
}
const bytes = new Uint8Array(await new Response(object.body).arrayBuffer());
await remoteSession.putFile(remotePath, bytes, {
contentType: object.contentType,
});
remoteAttachmentIndex.set(attachment.blobName, attachment.sizeBytes);
attachmentIndexChanged = true;
} }
const remotePath = `attachments/${attachment.blobName}`; if (attachmentIndexChanged) {
const object = await getBlobObject(env, attachment.blobName); await saveRemoteAttachmentIndex(remoteSession, remoteAttachmentIndex);
if (!object) {
throw new Error(`Attachment blob missing for ${attachment.blobName}`);
} }
const bytes = new Uint8Array(await new Response(object.body).arrayBuffer());
await remoteSession.putFile(remotePath, bytes, {
contentType: object.contentType,
});
remoteAttachmentIndex.set(attachment.blobName, attachment.sizeBytes);
attachmentIndexChanged = true;
}
if (attachmentIndexChanged) {
await saveRemoteAttachmentIndex(remoteSession, remoteAttachmentIndex);
} }
let upload: Awaited<ReturnType<typeof uploadBackupArchive>> | null = null; let upload: Awaited<ReturnType<typeof uploadBackupArchive>> | null = null;
for (let attempt = 1; attempt <= maxArchiveUploadAttempts; attempt++) { for (let attempt = 1; attempt <= maxArchiveUploadAttempts; attempt++) {