feat: not working download zip file
This commit is contained in:
@@ -153,6 +153,12 @@ class ApiClient {
|
|||||||
return this.request(`/posts/${postId}/metadata`);
|
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 ====================
|
// ==================== RAG Search ====================
|
||||||
|
|
||||||
async searchRAG(query, userId, page = 1, limit = 30) {
|
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 = () => {
|
const handleEnded = () => {
|
||||||
setIsPlaying(false)
|
setIsPlaying(false)
|
||||||
setCurrentTime(0)
|
setCurrentTime(0)
|
||||||
@@ -156,6 +174,15 @@ export default function AudioPostCard({ post }) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<button className="text-gray-500 hover:text-gray-700">
|
||||||
<MoreVertical size={18} />
|
<MoreVertical size={18} />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user