import { useParams } from 'react-router-dom'; import { useEffect, useRef, useState } from "react"; import Playbar from "./../components/Playbar"; import PlaybackSlider from "./../components/PlaybackSlider"; import ClipRangeSlider from "./../components/ClipRangeSlider"; import ClipConfig from "./../components/ClipConfig"; import {editFile, getMetadata, processFile, getProgress} from "../utils/Endpoints" import type { VideoMetadata } from "../utils/types.ts"; import BlueButton from "../components/buttons/BlueButton.tsx"; const ClipEdit = () => { const { id } = useParams(); const videoRef = useRef(null); const videoUrl = `/api/v1/download/input/${id}` const [metadata, setMetadata] = useState(null); const [playbackValue, setPlaybackValue] = useState(0); const [outputMetadata, setOutputMetadata] = useState({ // default values startPoint: 0, endPoint: 5, width: 1280, height: 720, fps: 30, fileSize: 10000 }); const [progress, setProgress] = useState(0); const [downloadable, setDownloadable] = useState(false); const sendData = async() => { if (!id) return; setDownloadable(false); await editFile(id, outputMetadata); const processed = await processFile(id); if (!processed) { console.log("Failed to process file"); return; } const interval = setInterval(async () => { const progress = await getProgress(id); setProgress(progress); if (progress >= 1) { clearInterval(interval); setDownloadable(true); console.log("Downloadable"); } }, 500); } 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); }; useEffect(() => { if (!id) return; getMetadata(id) .then((data) => setMetadata(data ?? null)) .catch((err) => console.error("Metadata fetch failed:", err)); }, [id]); return (
{metadata &&
}
Export { downloadable ? ( handleDownload(id)}> Download ) :( ) }
); } export default ClipEdit;