feat: not working download zip file

This commit is contained in:
Mann Patel
2026-02-15 02:22:03 -07:00
parent 30392a7cd9
commit 73f99d59dc
2 changed files with 47 additions and 14 deletions

View File

@@ -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) {

View File

@@ -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 }) {
</span>
</div>
</div>
{post.status === "ready" && (
<button
onClick={handleDownload}
className="mt-2 px-3 py-1 bg-[#f4b840] text-black rounded hover:bg-[#e5a930] transition-colors"
>
Download Post
</button>
)}
<button className="text-gray-500 hover:text-gray-700">
<MoreVertical size={18} />
</button>