From 6e296320e0dc4202d24707561985a00ae5e81f0e Mon Sep 17 00:00:00 2001 From: DVD Date: Wed, 19 Jul 2023 09:45:00 -0700 Subject: [PATCH] fix: skip attachment import if undefined --- packages/backend/src/misc/process-masto-notes.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/backend/src/misc/process-masto-notes.ts b/packages/backend/src/misc/process-masto-notes.ts index 0333a17c17..1327b4cff0 100644 --- a/packages/backend/src/misc/process-masto-notes.ts +++ b/packages/backend/src/misc/process-masto-notes.ts @@ -44,6 +44,13 @@ function processMastoFile(fn: string, path: string, dir: string, uid: string) { logger.info(`Unzip to ${dir}`); const outbox = JSON.parse(fs.readFileSync(`${dir}/outbox.json`)); for (const note of outbox.orderedItems) { + // Skip if attachment is undefined or not iterable + if ( + note.object.attachment == null || + !note.object.attachment[Symbol.iterator] + ) { + continue; + } for (const attachment of note.object.attachment) { const url = attachment.url.replaceAll("..", ""); if (url.indexOf("\0") !== -1) {