fix: Refactor attachment downloads during export to use promises (#5294
* Refactor attachment downloads during export to use promises instead of streams Date attachments in zip file correctly * tsc
This commit is contained in:
@@ -9,7 +9,6 @@ import DocumentHelper from "@server/models/helpers/DocumentHelper";
|
||||
import ZipHelper from "@server/utils/ZipHelper";
|
||||
import { serializeFilename } from "@server/utils/fs";
|
||||
import parseAttachmentIds from "@server/utils/parseAttachmentIds";
|
||||
import { getFileByKey } from "@server/utils/s3";
|
||||
import ExportTask from "./ExportTask";
|
||||
|
||||
export default abstract class ExportDocumentTreeTask extends ExportTask {
|
||||
@@ -65,13 +64,11 @@ export default abstract class ExportDocumentTreeTask extends ExportTask {
|
||||
key: attachment.key,
|
||||
});
|
||||
|
||||
const stream = getFileByKey(attachment.key);
|
||||
const dir = path.dirname(pathInZip);
|
||||
if (stream) {
|
||||
zip.file(path.join(dir, attachment.key), stream, {
|
||||
createFolders: true,
|
||||
});
|
||||
}
|
||||
zip.file(path.join(dir, attachment.key), attachment.buffer, {
|
||||
date: attachment.updatedAt,
|
||||
createFolders: true,
|
||||
});
|
||||
} catch (err) {
|
||||
Logger.error(
|
||||
`Failed to add attachment to archive: ${attachment.key}`,
|
||||
|
||||
@@ -16,7 +16,6 @@ import { CollectionJSONExport, JSONExportMetadata } from "@server/types";
|
||||
import ZipHelper from "@server/utils/ZipHelper";
|
||||
import { serializeFilename } from "@server/utils/fs";
|
||||
import parseAttachmentIds from "@server/utils/parseAttachmentIds";
|
||||
import { getFileByKey } from "@server/utils/s3";
|
||||
import packageJson from "../../../package.json";
|
||||
import ExportTask from "./ExportTask";
|
||||
|
||||
@@ -86,12 +85,10 @@ export default class ExportJSONTask extends ExportTask {
|
||||
await Promise.all(
|
||||
attachments.map(async (attachment) => {
|
||||
try {
|
||||
const stream = getFileByKey(attachment.key);
|
||||
if (stream) {
|
||||
zip.file(attachment.key, stream, {
|
||||
createFolders: true,
|
||||
});
|
||||
}
|
||||
zip.file(attachment.key, attachment.buffer, {
|
||||
date: attachment.updatedAt,
|
||||
createFolders: true,
|
||||
});
|
||||
|
||||
output.attachments[attachment.id] = {
|
||||
...omit(presentAttachment(attachment), "url"),
|
||||
|
||||
Reference in New Issue
Block a user