Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 5 additions & 7 deletions src/components/VideoPlayerContexts/VideoPopoverMenuContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import _ from 'underscore';
import * as Expensicons from '@components/Icon/Expensicons';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
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]);
const {isOffline} = useNetwork();
Expand All @@ -26,11 +26,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(() => {
const items = [];
Expand Down
8 changes: 4 additions & 4 deletions src/libs/fileDownload/FileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
Expand All @@ -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;
Expand Down