Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Invalid file is downloaded when uploading invalid file and downloading from receipt view #35536

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
thumbnail={receiptURIs.thumbnail}
image={receiptURIs.image}
isLocalFile={receiptURIs.isLocalFile}
filename={receiptURIs.filename || transaction.filename}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a fallback value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to use transaction.filename in case it's pending waypoint. But after checking, we don't need it anymore

transaction={transaction}
enablePreviewModal
canEditReceipt={canEditReceipt}
Expand Down
7 changes: 5 additions & 2 deletions src/components/ReportActionItem/ReportActionItemImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type ReportActionItemImageProps = {

/** whether the receipt can be replaced */
canEditReceipt?: boolean;

/** Filename of attachment */
filename?: string;
};

/**
Expand All @@ -42,7 +45,7 @@ type ReportActionItemImageProps = {
* and optional preview modal as well.
*/

function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false}: ReportActionItemImageProps) {
function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, transaction, canEditReceipt = false, isLocalFile = false, filename}: ReportActionItemImageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const imageSource = tryResolveUrlFromApiRoot(image ?? '');
Expand Down Expand Up @@ -86,7 +89,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal = false, tr
isReceiptAttachment
canEditReceipt={canEditReceipt}
allowDownload
originalFileName={transaction?.filename}
originalFileName={filename}
>
{({show}) => (
<PressableWithoutFocus
Expand Down
9 changes: 5 additions & 4 deletions src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ThumbnailAndImageURI = {
thumbnail: ImageSourcePropType | string | null;
transaction?: Transaction;
isLocalFile?: boolean;
filename?: string;
};

type FileNameAndExtension = {
Expand Down Expand Up @@ -45,16 +46,16 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
const hasEReceipt = transaction?.hasEReceipt;

if (hasEReceipt) {
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction};
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction, filename};
}

// For local files, we won't have a thumbnail yet
if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) {
return {thumbnail: null, image: path, isLocalFile: true};
return {thumbnail: null, image: path, isLocalFile: true, filename};
}

if (isReceiptImage) {
return {thumbnail: `${path}.1024.jpg`, image: path};
return {thumbnail: `${path}.1024.jpg`, image: path, filename};
}

const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension;
Expand All @@ -72,7 +73,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
}

const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path.startsWith('/');
return {thumbnail: image, image: path, isLocalFile};
return {thumbnail: image, image: path, isLocalFile, filename};
}

// eslint-disable-next-line import/prefer-default-export
Expand Down
Loading