Skip to content

Commit

Permalink
Revert "Fix: Handle undefined fileName during attachment download"
Browse files Browse the repository at this point in the history
This reverts commit 0060380.

Revert "Fix: Add fallback name for attachments lacking the original filename"

This reverts commit c1536f9.
  • Loading branch information
kidroca committed Nov 6, 2023
1 parent c1536f9 commit 474ba31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Image from '@components/Image';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import styles from '@styles/styles';
import * as StyleUtils from '@styles/StyleUtils';
import CONST from '@src/CONST';
Expand All @@ -22,15 +21,14 @@ const propTypes = {
url: PropTypes.string.isRequired,

/** image file name */
fileName: PropTypes.string,
fileName: PropTypes.string.isRequired,

onError: PropTypes.func,
};

const defaultProps = {
isAuthTokenRequired: false,
onError: () => {},
fileName: '',
};

function ImageView({isAuthTokenRequired, url, fileName, onError}) {
Expand All @@ -51,7 +49,6 @@ function ImageView({isAuthTokenRequired, url, fileName, onError}) {

const scrollableRef = useRef(null);
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const accessibilityLabel = fileName || FileUtils.getAttachmentName(url);

/**
* @param {Number} newContainerWidth
Expand Down Expand Up @@ -266,7 +263,7 @@ function ImageView({isAuthTokenRequired, url, fileName, onError}) {
onPressIn={onContainerPressIn}
onPress={onContainerPress}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGE}
accessibilityLabel={accessibilityLabel}
accessibilityLabel={fileName}
>
<Image
source={{uri: url}}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/fileDownload/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function hasAndroidPermission() {
/**
* Handling the download
* @param {String} url
* @param {String} [fileName]
* @param {String} fileName
* @returns {Promise<Void>}
*/
function handleDownload(url, fileName) {
Expand All @@ -41,7 +41,7 @@ function handleDownload(url, fileName) {

// Android files will download to Download directory
const path = dirs.DownloadDir;
const attachmentName = fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(url);
const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(url);

const isLocalFile = url.startsWith('file://');

Expand Down Expand Up @@ -96,7 +96,7 @@ function handleDownload(url, fileName) {
/**
* Checks permission and downloads the file for Android
* @param {String} url
* @param {String} [fileName]
* @param {String} fileName
* @returns {Promise<Void>}
*/
export default function fileDownload(url, fileName) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/fileDownload/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ function downloadVideo(fileUrl, fileName) {
/**
* Download the file based on type(image, video, other file types)for iOS
* @param {String} fileUrl
* @param {String} [fileName]
* @param {String} fileName
* @returns {Promise<Void>}
*/
export default function fileDownload(fileUrl, fileName) {
return new Promise((resolve) => {
let fileDownloadPromise = null;
const fileType = FileUtils.getFileType(fileUrl);
const attachmentName = fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(fileUrl);
const attachmentName = FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(fileUrl);

switch (fileType) {
case CONST.ATTACHMENT_FILE_TYPE.IMAGE:
Expand Down
4 changes: 2 additions & 2 deletions src/libs/fileDownload/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as FileUtils from './FileUtils';
/**
* Downloading attachment in web, desktop
* @param {String} url
* @param {String} [fileName]
* @param {String} fileName
* @returns {Promise}
*/
export default function fileDownload(url, fileName) {
Expand All @@ -33,7 +33,7 @@ export default function fileDownload(url, fileName) {
link.style.display = 'none';
link.setAttribute(
'download',
fileName ? FileUtils.appendTimeToFileName(fileName) : FileUtils.getAttachmentName(url), // generating the file name
FileUtils.appendTimeToFileName(fileName) || FileUtils.getAttachmentName(url), // generating the file name
);

// Append to html link element page
Expand Down

0 comments on commit 474ba31

Please sign in to comment.