diff --git a/client/src/Pages/ProcessingPage.tsx b/client/src/Pages/ProcessingPage.tsx index 797b6a8..df2e7c8 100644 --- a/client/src/Pages/ProcessingPage.tsx +++ b/client/src/Pages/ProcessingPage.tsx @@ -8,7 +8,7 @@ import JSZip from "jszip"; function ProcessingPage() { const navigate = useNavigate(); - const { mediaFile, response, setExtractedFiles } = useMediaContext(); + const { mediaFile, response, setExtractedFiles, setDownloadedFileURL } = useMediaContext(); const [progress, setProgress] = useState(0); const [statusText, setStatusText] = useState("Analyzing media..."); @@ -40,7 +40,7 @@ function ProcessingPage() { } }; - const fetchDownload = async () => { + const fetchZipDownload = async () => { try { setStatusText("Fetching Results..."); @@ -58,6 +58,30 @@ function ProcessingPage() { console.error("Error fetching download:", error); } }; + + const fetchDownload = async () => { + try { + setStatusText("Fetching Results..."); + + const res = await axios.get(`/api/download?file_uuid=${response.file_uuid}`, { + responseType: "blob", + }); + + if (res.status === 200) { + console.log("Download successful"); + const blob = new Blob([res.data], { type: "audio/wav" }); + const fileURL = URL.createObjectURL(blob); + + setDownloadedFileURL( fileURL ); + setProgress(100); + + } else { + console.log("Failed to download the file"); + } + } catch (error) { + console.error("Error fetching download:", error); + } + }; const handleDownload = async (downloadData: Blob) => { @@ -89,10 +113,10 @@ function ProcessingPage() { processStep("/api/trim", () => { if (response.audio_class === "Music") { processStep("/api/resample", () => { - processStep("/api/separate", () => fetchDownload(), 90, "Separating music into vocals, bass, drums and other..."); + processStep("/api/separate", () => fetchZipDownload(), 90, "Separating music into vocals, bass, drums and other..."); }, 75, "Resampling audio to 44100Hz...", { sr: "44100" }); } else { - processStep("/api/noisereduce", () => setProgress(100), 100, "Reducing background noise from the audio..."); + processStep("/api/noisereduce", () => fetchDownload(), 90, "Reducing background noise from the audio..."); } }, 50, "Trimming silent parts from the audio..."); }, 25, "Normalizing audio frequency..."); diff --git a/client/src/Pages/ResultsPage.tsx b/client/src/Pages/ResultsPage.tsx index b4b9c70..1c0e91d 100644 --- a/client/src/Pages/ResultsPage.tsx +++ b/client/src/Pages/ResultsPage.tsx @@ -21,7 +21,7 @@ import { useMediaContext } from '../contexts/MediaContext'; function ResultsPage() { const navigate = useNavigate(); - const { mediaFile, response, extractedFiles } = useMediaContext(); + const { mediaFile, response, extractedFiles, downloadedFileURL } = useMediaContext(); console.log("Extracted files are", extractedFiles); // const [isPlaying, setIsPlaying] = useState(false); const audioRefs = [useRef(null), useRef(null), useRef(null),useRef(null)]; @@ -104,9 +104,12 @@ function ResultsPage() { )) ) : ( + + {mediaFile?.name} +