feat: not working download zip file
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user