From d57ec3911394f24478ab67cc20d9f866a8a873b3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 25 May 2023 22:09:08 -0400 Subject: [PATCH] fix: Attachments in imported JSON reference files on previous instance closes #5361 --- server/queues/tasks/ImportJSONTask.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/server/queues/tasks/ImportJSONTask.ts b/server/queues/tasks/ImportJSONTask.ts index 9ece4f612..3b576b261 100644 --- a/server/queues/tasks/ImportJSONTask.ts +++ b/server/queues/tasks/ImportJSONTask.ts @@ -147,22 +147,14 @@ export default class ImportJSONTask extends ImportTask { // and replace them out with attachment redirect urls before continuing. for (const document of output.documents) { for (const attachment of output.attachments) { - const encodedPath = encodeURI(attachment.path); - - // Pull the collection and subdirectory out of the path name, upload - // folders in an export are relative to the document itself - const normalizedAttachmentPath = encodedPath.replace( - /(.*)uploads\//, - "uploads/" + const encodedPath = encodeURI( + `/api/attachments.redirect?id=${attachment.sourceId}` ); - const reference = `<<${attachment.id}>>`; - document.text = document.text - .replace(new RegExp(escapeRegExp(encodedPath), "g"), reference) - .replace( - new RegExp(`/?${escapeRegExp(normalizedAttachmentPath)}`, "g"), - reference - ); + document.text = document.text.replace( + new RegExp(escapeRegExp(encodedPath), "g"), + `<<${attachment.id}>>` + ); } }