Error loading attachment should not fail entire export. closes #6158

This commit is contained in:
Tom Moor
2023-11-15 20:38:54 -05:00
parent cf6a946c9c
commit a0b51b8c71
3 changed files with 66 additions and 48 deletions

View File

@@ -63,28 +63,34 @@ export default abstract class ExportDocumentTreeTask extends ExportTask {
// reference in the document with the path to the attachment in the zip
await Promise.all(
attachments.map(async (attachment) => {
try {
Logger.debug("task", `Adding attachment to archive`, {
documentId,
key: attachment.key,
});
Logger.debug("task", `Adding attachment to archive`, {
documentId,
key: attachment.key,
});
const dir = path.dirname(pathInZip);
zip.file(path.join(dir, attachment.key), attachment.buffer, {
const dir = path.dirname(pathInZip);
zip.file(
path.join(dir, attachment.key),
new Promise<Buffer>((resolve) => {
attachment.buffer.then(resolve).catch((err) => {
Logger.warn(`Failed to read attachment from storage`, {
attachmentId: attachment.id,
teamId: attachment.teamId,
error: err.message,
});
resolve(Buffer.from(""));
});
}),
{
date: attachment.updatedAt,
createFolders: true,
});
}
);
text = text.replace(
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
encodeURI(attachment.key)
);
} catch (err) {
Logger.error(
`Failed to add attachment to archive: ${attachment.key}`,
err
);
}
text = text.replace(
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
encodeURI(attachment.key)
);
})
);

View File

@@ -94,22 +94,28 @@ export default class ExportJSONTask extends ExportTask {
await Promise.all(
attachments.map(async (attachment) => {
try {
zip.file(attachment.key, attachment.buffer, {
zip.file(
attachment.key,
new Promise<Buffer>((resolve) => {
attachment.buffer.then(resolve).catch((err) => {
Logger.warn(`Failed to read attachment from S3`, {
attachmentId: attachment.id,
teamId: attachment.teamId,
error: err.message,
});
resolve(Buffer.from(""));
});
}),
{
date: attachment.updatedAt,
createFolders: true,
});
}
);
output.attachments[attachment.id] = {
...omit(presentAttachment(attachment), "url"),
key: attachment.key,
};
} catch (err) {
Logger.error(
`Failed to add attachment to archive: ${attachment.key}`,
err
);
}
output.attachments[attachment.id] = {
...omit(presentAttachment(attachment), "url"),
key: attachment.key,
};
})
);