mirror of
https://github.com/Qortal/q-tube.git
synced 2025-02-14 11:15:52 +00:00
Merge pull request #5 from lgedgar/save-as-filename
Construct "save as" filename from video title if possible
This commit is contained in:
commit
8c89f305a3
@ -113,7 +113,13 @@ export default function FileElement({
|
|||||||
service: service,
|
service: service,
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
});
|
});
|
||||||
filename = res?.filename || filename;
|
// TODO: previously this was "always" overriding the filename
|
||||||
|
// here, but i think caller filename should be honored if set.
|
||||||
|
// if there was a reason to always override, then maybe this
|
||||||
|
// should be changed back..?
|
||||||
|
if (!filename) {
|
||||||
|
filename = res?.filename || filename;
|
||||||
|
}
|
||||||
mimeType = res?.mimeType || mimeType;
|
mimeType = res?.mimeType || mimeType;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
@ -170,6 +170,38 @@ export const VideoContent = () => {
|
|||||||
|
|
||||||
const [videoData, setVideoData] = useState<any>(null);
|
const [videoData, setVideoData] = useState<any>(null);
|
||||||
|
|
||||||
|
const saveAsFilename = useMemo(() => {
|
||||||
|
|
||||||
|
// nb. we prefer to construct the local filename to use for
|
||||||
|
// saving, from the video "title" when possible
|
||||||
|
if (videoData?.title) {
|
||||||
|
|
||||||
|
// figure out filename extension
|
||||||
|
let ext = ".mp4";
|
||||||
|
if (videoData?.filename) {
|
||||||
|
// nb. this regex copied from https://stackoverflow.com/a/680982
|
||||||
|
const re = /(?:\.([^.]+))?$/;
|
||||||
|
const match = re.exec(videoData.filename);
|
||||||
|
if (match[1]) {
|
||||||
|
ext = "." + match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return videoData.title + ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise use QDN filename if applicable
|
||||||
|
if (videoData?.filename) {
|
||||||
|
return videoData.filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this was the previous value, leaving here as the
|
||||||
|
// fallback for now even though it probably is not needed..?
|
||||||
|
return videoData?.filename ||
|
||||||
|
videoData?.title?.slice(0, 20) + ".mp4";
|
||||||
|
|
||||||
|
}, [videoData]);
|
||||||
|
|
||||||
const hashMapVideos = useSelector(
|
const hashMapVideos = useSelector(
|
||||||
(state: RootState) => state.video.hashMapVideos
|
(state: RootState) => state.video.hashMapVideos
|
||||||
);
|
);
|
||||||
@ -370,9 +402,7 @@ export const VideoContent = () => {
|
|||||||
<FileElement
|
<FileElement
|
||||||
fileInfo={{
|
fileInfo={{
|
||||||
...videoReference,
|
...videoReference,
|
||||||
filename:
|
filename: saveAsFilename,
|
||||||
videoData?.filename ||
|
|
||||||
videoData?.title?.slice(0, 20) + ".mp4",
|
|
||||||
mimeType: videoData?.videoType || '"video/mp4',
|
mimeType: videoData?.videoType || '"video/mp4',
|
||||||
}}
|
}}
|
||||||
title={videoData?.filename || videoData?.title?.slice(0, 20)}
|
title={videoData?.filename || videoData?.title?.slice(0, 20)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user