Error loading attachment should not fail entire export. closes #6158
This commit is contained in:
@@ -63,28 +63,34 @@ export default abstract class ExportDocumentTreeTask extends ExportTask {
|
|||||||
// reference in the document with the path to the attachment in the zip
|
// reference in the document with the path to the attachment in the zip
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
attachments.map(async (attachment) => {
|
attachments.map(async (attachment) => {
|
||||||
try {
|
|
||||||
Logger.debug("task", `Adding attachment to archive`, {
|
Logger.debug("task", `Adding attachment to archive`, {
|
||||||
documentId,
|
documentId,
|
||||||
key: attachment.key,
|
key: attachment.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
const dir = path.dirname(pathInZip);
|
const dir = path.dirname(pathInZip);
|
||||||
zip.file(path.join(dir, attachment.key), attachment.buffer, {
|
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,
|
date: attachment.updatedAt,
|
||||||
createFolders: true,
|
createFolders: true,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
text = text.replace(
|
text = text.replace(
|
||||||
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
|
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
|
||||||
encodeURI(attachment.key)
|
encodeURI(attachment.key)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
|
||||||
Logger.error(
|
|
||||||
`Failed to add attachment to archive: ${attachment.key}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -94,22 +94,28 @@ export default class ExportJSONTask extends ExportTask {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
attachments.map(async (attachment) => {
|
attachments.map(async (attachment) => {
|
||||||
try {
|
zip.file(
|
||||||
zip.file(attachment.key, attachment.buffer, {
|
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,
|
date: attachment.updatedAt,
|
||||||
createFolders: true,
|
createFolders: true,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
output.attachments[attachment.id] = {
|
output.attachments[attachment.id] = {
|
||||||
...omit(presentAttachment(attachment), "url"),
|
...omit(presentAttachment(attachment), "url"),
|
||||||
key: attachment.key,
|
key: attachment.key,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
|
||||||
Logger.error(
|
|
||||||
`Failed to add attachment to archive: ${attachment.key}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -574,26 +574,32 @@ router.post(
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
attachments.map(async (attachment) => {
|
attachments.map(async (attachment) => {
|
||||||
try {
|
|
||||||
const location = path.join(
|
const location = path.join(
|
||||||
"attachments",
|
"attachments",
|
||||||
`${attachment.id}.${mime.extension(attachment.contentType)}`
|
`${attachment.id}.${mime.extension(attachment.contentType)}`
|
||||||
);
|
);
|
||||||
zip.file(location, attachment.buffer, {
|
zip.file(
|
||||||
|
location,
|
||||||
|
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,
|
date: attachment.updatedAt,
|
||||||
createFolders: true,
|
createFolders: true,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
|
new RegExp(escapeRegExp(attachment.redirectUrl), "g"),
|
||||||
location
|
location
|
||||||
);
|
);
|
||||||
} catch (err) {
|
|
||||||
Logger.error(
|
|
||||||
`Failed to add attachment to archive: ${attachment.id}`,
|
|
||||||
err
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user