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: Video - Invalid file is downloaded when downloading video. #37163

Merged
merged 7 commits into from
Feb 26, 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/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ const CONST = {
ATTACHMENT_THUMBNAIL_WIDTH_ATTRIBUTE: 'data-expensify-width',
ATTACHMENT_THUMBNAIL_HEIGHT_ATTRIBUTE: 'data-expensify-height',
ATTACHMENT_DURATION_ATTRIBUTE: 'data-expensify-duration',
ENCRYPTED_AUTH_TOKEN_KEY: 'encryptedAuthToken',

ATTACHMENT_PICKER_TYPE: {
FILE: 'file',
Expand Down
5 changes: 3 additions & 2 deletions src/components/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Image as RNImage} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import useNetwork from '@hooks/useNetwork';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {defaultProps, imagePropTypes} from './imagePropTypes';
import RESIZE_MODES from './resizeModes';
Expand All @@ -21,8 +22,8 @@ function Image(props) {
// There is currently a `react-native-web` bug preventing the authToken being passed
// in the headers of the image request so the authToken is added as a query param.
// On native the authToken IS passed in the image request headers
const authToken = lodashGet(session, 'encryptedAuthToken', null);
return {uri: `${propsSource.uri}?encryptedAuthToken=${encodeURIComponent(authToken)}`};
const authToken = lodashGet(session, CONST.ENCRYPTED_AUTH_TOKEN_KEY, null);
return {uri: `${propsSource.uri}?${CONST.ENCRYPTED_AUTH_TOKEN_KEY}=${encodeURIComponent(authToken)}`};
}
return propsSource;
// The session prop is not required, as it causes the image to reload whenever the session changes. For more information, please refer to issue #26034.
Expand Down
3 changes: 2 additions & 1 deletion src/libs/addEncryptedAuthTokenToURL.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

let encryptedAuthToken = '';
Expand All @@ -11,5 +12,5 @@ Onyx.connect({
* Add encryptedAuthToken to this attachment URL
*/
export default function (url: string) {
return `${url}?encryptedAuthToken=${encodeURIComponent(encryptedAuthToken)}`;
return `${url}?${CONST.ENCRYPTED_AUTH_TOKEN_KEY}=${encodeURIComponent(encryptedAuthToken)}`;
}
14 changes: 13 additions & 1 deletion src/libs/fileDownload/FileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ function showCameraPermissionsAlert() {
* with underscores.
*/
function getFileName(url: string): string {
const fileName = url.split(/[#?/]/).pop() ?? '';
let fileName = url;

// Remove encryptedAuthToken if exists
if (fileName.includes(`?${CONST.ENCRYPTED_AUTH_TOKEN_KEY}=`)) {
fileName = fileName.split(`?${CONST.ENCRYPTED_AUTH_TOKEN_KEY}=`)[0];
}

fileName = fileName.split(/[#?/]/).pop() ?? '';

if (!fileName) {
Log.warn('[FileUtils] Could not get attachment name', {url});
}
Krishna2323 marked this conversation as resolved.
Show resolved Hide resolved

if (!fileName) {
Log.warn('[FileUtils] Could not get attachment name', {url});
}
Expand Down
Loading