ADD download button functionality
This commit is contained in:
@@ -15,8 +15,10 @@ function exportFile(uuid: string,
|
|||||||
height: number,
|
height: number,
|
||||||
fps: number,
|
fps: number,
|
||||||
fileSize: number,
|
fileSize: number,
|
||||||
setProgress: Function) {
|
setProgress: Function,
|
||||||
|
setDownloadable: Function) {
|
||||||
|
|
||||||
|
setDownloadable(false);
|
||||||
const metadata: VideoMetadata = {
|
const metadata: VideoMetadata = {
|
||||||
startPoint: startPoint,
|
startPoint: startPoint,
|
||||||
endPoint: endPoint,
|
endPoint: endPoint,
|
||||||
@@ -39,13 +41,16 @@ function exportFile(uuid: string,
|
|||||||
|
|
||||||
if (result >= 1) {
|
if (result >= 1) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
|
setDownloadable(true);
|
||||||
console.log('Progress complete');
|
console.log('Progress complete');
|
||||||
|
} else {
|
||||||
|
setDownloadable(false);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to fetch progress', err);
|
console.error('Failed to fetch progress', err);
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
}
|
}
|
||||||
}, 500); // 0.5 seconds
|
}, 200); // 0.5 seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function VideoId() {
|
export default function VideoId() {
|
||||||
@@ -62,6 +67,7 @@ export default function VideoId() {
|
|||||||
const [fileSize, setFileSize] = useState(10);
|
const [fileSize, setFileSize] = useState(10);
|
||||||
|
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
|
const [downloadable, setDownloadable] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -73,9 +79,29 @@ export default function VideoId() {
|
|||||||
|
|
||||||
const sendData = () => {
|
const sendData = () => {
|
||||||
if (!id) return
|
if (!id) return
|
||||||
exportFile(id,clipRangeValue[0], clipRangeValue[1], width, height, fps, fileSize, setProgress);
|
exportFile(id,clipRangeValue[0], clipRangeValue[1], width, height, fps, fileSize, setProgress, setDownloadable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDownload = async (filename: string | undefined) => {
|
||||||
|
if (!filename) return;
|
||||||
|
const response = await fetch(`/api/v1/download/output/${id}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error('Download failed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await response.blob();
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = filename;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={"grid grid-cols-[70%_30%]"}>
|
<div className={"grid grid-cols-[70%_30%]"}>
|
||||||
<video
|
<video
|
||||||
@@ -127,13 +153,19 @@ export default function VideoId() {
|
|||||||
Export
|
Export
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<progress
|
{ downloadable ?
|
||||||
value={progress}
|
(<button
|
||||||
className={"bg-gray-200 rounded-lg h-1"}>
|
className={"bg-primary text-text p-2 rounded-lg hover:bg-primary-pressed h-10"}
|
||||||
</progress>
|
onClick={() => handleDownload(id)}>
|
||||||
|
Download
|
||||||
|
</button>)
|
||||||
|
:(
|
||||||
|
<progress
|
||||||
|
value={progress}
|
||||||
|
className={"bg-gray-200 rounded-lg h-1"}>
|
||||||
|
</progress> )
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user