From f300dbb6ace1e8f00908ed05969abeb97d167c23 Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Fri, 17 Nov 2023 07:27:34 +0100 Subject: [PATCH 1/2] fix image not downloading in offline mode --- src/CONST.ts | 1 + .../AttachmentCarousel/extractAttachmentsFromReport.js | 2 +- src/libs/fileDownload/index.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 69ca8256cc6f..a1424b28c15f 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -961,6 +961,7 @@ const CONST = { ATTACHMENT_SOURCE_ATTRIBUTE: 'data-expensify-source', ATTACHMENT_PREVIEW_ATTRIBUTE: 'src', ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE: 'data-name', + ATTACHMENT_LOCAL_URL_PREFIX: ['blob:', 'file:'], ATTACHMENT_PICKER_TYPE: { FILE: 'file', diff --git a/src/components/Attachments/AttachmentCarousel/extractAttachmentsFromReport.js b/src/components/Attachments/AttachmentCarousel/extractAttachmentsFromReport.js index 28af6b511641..0f1fa15c99ca 100644 --- a/src/components/Attachments/AttachmentCarousel/extractAttachmentsFromReport.js +++ b/src/components/Attachments/AttachmentCarousel/extractAttachmentsFromReport.js @@ -54,7 +54,7 @@ function extractAttachmentsFromReport(parentReportAction, reportActions, transac if (TransactionUtils.hasReceipt(transaction)) { const {image} = ReceiptUtils.getThumbnailAndImageURIs(transaction); - const isLocalFile = typeof image === 'string' && (image.startsWith('blob:') || image.startsWith('file:')); + const isLocalFile = typeof image === 'string' && _.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => image.startsWith(prefix)); attachments.unshift({ source: tryResolveUrlFromApiRoot(image), isAuthTokenRequired: !isLocalFile, diff --git a/src/libs/fileDownload/index.js b/src/libs/fileDownload/index.js index d1fa968b665f..002594244def 100644 --- a/src/libs/fileDownload/index.js +++ b/src/libs/fileDownload/index.js @@ -1,6 +1,8 @@ +import _ from 'lodash'; import * as ApiUtils from '@libs/ApiUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import * as Link from '@userActions/Link'; +import CONST from '@src/CONST'; import * as FileUtils from './FileUtils'; /** @@ -11,7 +13,7 @@ import * as FileUtils from './FileUtils'; */ export default function fileDownload(url, fileName) { const resolvedUrl = tryResolveUrlFromApiRoot(url); - if (!resolvedUrl.startsWith(ApiUtils.getApiRoot())) { + if (!resolvedUrl.startsWith(ApiUtils.getApiRoot()) && !_.some(CONST.ATTACHMENT_LOCAL_URL_PREFIX, (prefix) => resolvedUrl.startsWith(prefix))) { // Different origin URLs might pose a CORS issue during direct downloads. // Opening in a new tab avoids this limitation, letting the browser handle the download. Link.openExternalLink(url); From bd1706af6536183d69bd89ba5bdf1c718df477c9 Mon Sep 17 00:00:00 2001 From: mkhutornyi Date: Fri, 17 Nov 2023 08:27:52 +0100 Subject: [PATCH 2/2] retrigger