From 73f99d59dc99eb5bde6cdfdb278937d953bd4e8d Mon Sep 17 00:00:00 2001 From: Mann Patel <130435633+Patel-Mann@users.noreply.github.com> Date: Sun, 15 Feb 2026 02:22:03 -0700 Subject: [PATCH] feat: not working download zip file --- frontend/src/api.js | 18 ++++++---- frontend/src/components/AudioPostCard.jsx | 43 ++++++++++++++++++----- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/frontend/src/api.js b/frontend/src/api.js index 9bcd624..b7f6f6a 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -41,7 +41,7 @@ class ApiClient { } // ==================== Auth ==================== - + async register(email, password, displayName = null) { return this.request('/auth/register', { method: 'POST', @@ -58,12 +58,12 @@ class ApiClient { method: 'POST', body: JSON.stringify({ email, password }), }); - + // Store user ID for subsequent requests if (response.user?.user_id) { this.setUserId(response.user.user_id); } - + return response; } @@ -81,7 +81,7 @@ class ApiClient { async uploadPost(formData) { const url = `${this.baseUrl}/posts/upload`; - + try { const response = await fetch(url, { method: 'POST', @@ -103,7 +103,7 @@ class ApiClient { async getPosts(params = {}) { const queryParams = new URLSearchParams(); - + if (params.page) queryParams.append('page', params.page); if (params.limit) queryParams.append('limit', params.limit); if (params.visibility) queryParams.append('visibility', params.visibility); @@ -153,6 +153,12 @@ class ApiClient { return this.request(`/posts/${postId}/metadata`); } + async exportPost(postId) { + const response = await fetch(`/api/posts/${postId}/download`, { method: "GET" }); + if (!response.ok) throw new Error(`Failed to download post: ${response.statusText}`); + return await response.blob(); // returns proper Blob ready for download +} + // ==================== RAG Search ==================== async searchRAG(query, userId, page = 1, limit = 30) { @@ -174,7 +180,7 @@ class ApiClient { async getAuditLogs(params = {}) { const queryParams = new URLSearchParams(); - + if (params.post_id) queryParams.append('post_id', params.post_id); if (params.user_id) queryParams.append('user_id', params.user_id); if (params.page) queryParams.append('page', params.page); diff --git a/frontend/src/components/AudioPostCard.jsx b/frontend/src/components/AudioPostCard.jsx index 33bcac0..af684ae 100644 --- a/frontend/src/components/AudioPostCard.jsx +++ b/frontend/src/components/AudioPostCard.jsx @@ -24,7 +24,7 @@ export default function AudioPostCard({ post }) { const now = new Date() const diffMs = now - date const diffMins = Math.floor(diffMs / 60000) - + if (diffMins < 60) return `${diffMins}m ago` if (diffMins < 1440) return `${Math.floor(diffMins / 60)}h ago` return `${Math.floor(diffMins / 1440)}d ago` @@ -42,7 +42,7 @@ export default function AudioPostCard({ post }) { if (post.status === 'ready' && !transcript && !loadingTranscript) { loadTranscript() } - + // Set audio source if available if (post.audio_url && audioRef.current) { console.log('Setting audio src to:', post.audio_url) @@ -75,7 +75,7 @@ export default function AudioPostCard({ post }) { const togglePlay = () => { if (!audioRef.current) return - + if (isPlaying) { audioRef.current.pause() } else { @@ -107,7 +107,7 @@ export default function AudioPostCard({ post }) { const x = e.clientX - rect.left const percentage = x / rect.width const newTime = percentage * duration - + if (audioRef.current) { audioRef.current.currentTime = newTime setCurrentTime(newTime) @@ -122,6 +122,24 @@ export default function AudioPostCard({ post }) { } } + const handleDownload = async () => { + try { + const zipBlob = await api.exportPost(post.post_id); + + const url = window.URL.createObjectURL(zipBlob); + const a = document.createElement("a"); + a.href = url; + a.download = `${post.title.replace(/\s+/g, "_")}.zip`; + document.body.appendChild(a); + a.click(); + a.remove(); + window.URL.revokeObjectURL(url); + } catch (err) { + console.error("Failed to download post:", err); + } + } + + const handleEnded = () => { setIsPlaying(false) setCurrentTime(0) @@ -156,6 +174,15 @@ export default function AudioPostCard({ post }) { + {post.status === "ready" && ( + +)} + @@ -185,7 +212,7 @@ export default function AudioPostCard({ post }) { />