Skip to content

Commit

Permalink
šŸ› fix(components/AttachmentModal): prevent downloading local file souā€¦
Browse files Browse the repository at this point in the history
ā€¦rces

Added a check to ensure local file sources (file: or blob:) are not
included in the download options. This avoids redundancy and potential
issues with file not found when attempting to download local files.
  • Loading branch information
kidroca committed Jul 29, 2024
1 parent cab7749 commit caf095f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ function AttachmentModal({
const {translate} = useLocalize();
const {isOffline} = useNetwork();

const isLocalSource = /^file:|^blob:/.test(`${sourceState}`);

Check failure on line 198 in src/components/AttachmentModal.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'sourceState' may use Object's default stringification format ('[object Object]') when stringified

Check failure on line 198 in src/components/AttachmentModal.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "AvatarSource" of template literal expression

useEffect(() => {
setFile(originalFileName ? {name: originalFileName} : undefined);
}, [originalFileName]);
Expand Down Expand Up @@ -413,7 +415,7 @@ function AttachmentModal({
},
});
}
if (!isOffline && allowDownload) {
if (!isOffline && allowDownload && !isLocalSource) {
menuItems.push({
icon: Expensicons.Download,
text: translate('common.download'),
Expand All @@ -440,7 +442,7 @@ function AttachmentModal({
let shouldShowThreeDotsButton = false;
if (!isEmptyObject(report)) {
headerTitleNew = translate(isReceiptAttachment ? 'common.receipt' : 'common.attachment');
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !shouldShowNotFoundPage && !isReceiptAttachment && !isOffline;
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !shouldShowNotFoundPage && !isReceiptAttachment && !isOffline && !isLocalSource;
shouldShowThreeDotsButton = isReceiptAttachment && isModalOpen && threeDotsMenuItems.length !== 0;
}
const context = useMemo(
Expand Down

0 comments on commit caf095f

Please sign in to comment.