feat: Add option to not include attachments in exported data (#5463)

This commit is contained in:
Tom Moor
2023-06-20 21:17:39 -04:00
committed by GitHub
parent 0e5a576439
commit eb62b961a4
13 changed files with 106 additions and 23 deletions

View File

@@ -25,7 +25,11 @@ export default class ExportJSONTask extends ExportTask {
// serial to avoid overloading, slow and steady wins the race
for (const collection of collections) {
await this.addCollectionToArchive(zip, collection);
await this.addCollectionToArchive(
zip,
collection,
fileOperation.includeAttachments
);
}
await this.addMetadataToArchive(zip, fileOperation);
@@ -52,7 +56,11 @@ export default class ExportJSONTask extends ExportTask {
);
}
private async addCollectionToArchive(zip: JSZip, collection: Collection) {
private async addCollectionToArchive(
zip: JSZip,
collection: Collection,
includeAttachments: boolean
) {
const output: CollectionJSONExport = {
collection: {
...omit(presentCollection(collection), ["url"]),
@@ -75,12 +83,14 @@ export default class ExportJSONTask extends ExportTask {
continue;
}
const attachments = await Attachment.findAll({
where: {
teamId: document.teamId,
id: parseAttachmentIds(document.text),
},
});
const attachments = includeAttachments
? await Attachment.findAll({
where: {
teamId: document.teamId,
id: parseAttachmentIds(document.text),
},
})
: [];
await Promise.all(
attachments.map(async (attachment) => {