3
0
mirror of https://github.com/Qortal/q-tube.git synced 2025-02-11 17:55:51 +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:
Qortal Dev 2024-01-19 16:09:46 -07:00 committed by GitHub
commit 8c89f305a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 4 deletions

View File

@ -113,7 +113,13 @@ export default function FileElement({
service: service,
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;
} catch (error) {

View File

@ -170,6 +170,38 @@ export const VideoContent = () => {
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(
(state: RootState) => state.video.hashMapVideos
);
@ -370,9 +402,7 @@ export const VideoContent = () => {
<FileElement
fileInfo={{
...videoReference,
filename:
videoData?.filename ||
videoData?.title?.slice(0, 20) + ".mp4",
filename: saveAsFilename,
mimeType: videoData?.videoType || '"video/mp4',
}}
title={videoData?.filename || videoData?.title?.slice(0, 20)}