diff --git a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js index 23d1aec1817c..964f39db7fcf 100644 --- a/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js +++ b/src/components/VideoPlayerContexts/VideoPopoverMenuContext.js @@ -3,15 +3,19 @@ import React, {useCallback, useContext, useMemo, useState} from 'react'; import _ from 'underscore'; import * as Expensicons from '@components/Icon/Expensicons'; import useLocalize from '@hooks/useLocalize'; +<<<<<<< HEAD +======= +import useNetwork from '@hooks/useNetwork'; +import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL'; +>>>>>>> 2509631b (Merge pull request #37163 from Krishna2323/krishna2323/issue/37092) import fileDownload from '@libs/fileDownload'; -import * as Url from '@libs/Url'; import CONST from '@src/CONST'; import {usePlaybackContext} from './PlaybackContext'; const VideoPopoverMenuContext = React.createContext(null); function VideoPopoverMenuContextProvider({children}) { - const {currentVideoPlayerRef} = usePlaybackContext(); + const {currentVideoPlayerRef, currentlyPlayingURL} = usePlaybackContext(); const {translate} = useLocalize(); const [currentPlaybackSpeed, setCurrentPlaybackSpeed] = useState(CONST.VIDEO_PLAYER.PLAYBACK_SPEEDS[2]); @@ -24,11 +28,9 @@ function VideoPopoverMenuContextProvider({children}) { ); const downloadAttachment = useCallback(() => { - currentVideoPlayerRef.current.getStatusAsync().then((status) => { - const sourceURI = `/${Url.getPathFromURL(status.uri)}`; - fileDownload(sourceURI); - }); - }, [currentVideoPlayerRef]); + const sourceURI = currentlyPlayingURL.startsWith('blob:') || currentlyPlayingURL.startsWith('file:') ? currentlyPlayingURL : addEncryptedAuthTokenToURL(currentlyPlayingURL); + fileDownload(sourceURI); + }, [currentlyPlayingURL]); const menuItems = useMemo( () => [ diff --git a/src/libs/fileDownload/FileUtils.ts b/src/libs/fileDownload/FileUtils.ts index 055abf140e64..70ab01f62466 100644 --- a/src/libs/fileDownload/FileUtils.ts +++ b/src/libs/fileDownload/FileUtils.ts @@ -80,14 +80,14 @@ function showCameraPermissionsAlert() { * Extracts a filename from a given URL and sanitizes it for file system usage. * * This function takes a URL as input and performs the following operations: - * 1. Extracts the last segment of the URL, which could be a file name, a path segment, - * or a query string parameter. + * 1. Extracts the last segment of the URL. * 2. Decodes the extracted segment from URL encoding to a plain string for better readability. * 3. Replaces any characters in the decoded string that are illegal in file names * with underscores. */ function getFileName(url: string): string { - const fileName = url.split(/[#?/]/).pop() ?? ''; + const fileName = url.split('/').pop()?.split('?')[0].split('#')[0] ?? ''; + if (!fileName) { Log.warn('[FileUtils] Could not get attachment name', {url}); } @@ -111,7 +111,7 @@ function getFileType(fileUrl: string): string | undefined { return; } - const fileName = fileUrl.split('/').pop()?.split('?')[0].split('#')[0]; + const fileName = getFileName(fileUrl); if (!fileName) { return;