Spaces:
Running
Running
use api axios instead of fetch
Browse files
components/my-projects/project-card.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
| 18 |
} from "@/components/ui/dropdown-menu";
|
| 19 |
import { ProjectType } from "@/types";
|
| 20 |
import { toast } from "sonner";
|
|
|
|
| 21 |
|
| 22 |
// from-red-500 to-red-500
|
| 23 |
// from-yellow-500 to-yellow-500
|
|
@@ -48,39 +49,16 @@ export function ProjectCard({
|
|
| 48 |
const handleDownload = async () => {
|
| 49 |
try {
|
| 50 |
toast.info("Preparing download...");
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
const response = await fetch(
|
| 54 |
-
`/deepsite/api/me/projects/${project.name}/download`,
|
| 55 |
-
{
|
| 56 |
-
credentials: "include",
|
| 57 |
-
headers: {
|
| 58 |
-
Accept: "application/zip",
|
| 59 |
-
},
|
| 60 |
-
}
|
| 61 |
-
);
|
| 62 |
-
|
| 63 |
-
if (!response.ok) {
|
| 64 |
-
const error = await response
|
| 65 |
-
.json()
|
| 66 |
-
.catch(() => ({ error: "Download failed" }));
|
| 67 |
-
toast.error(error.error || "Failed to download project");
|
| 68 |
-
return;
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
// Create blob from response
|
| 72 |
-
const blob = await response.blob();
|
| 73 |
-
|
| 74 |
-
// Create download link
|
| 75 |
const url = window.URL.createObjectURL(blob);
|
| 76 |
const link = document.createElement("a");
|
| 77 |
link.href = url;
|
| 78 |
link.download = `${project.name.replace(/\//g, "-")}.zip`;
|
| 79 |
document.body.appendChild(link);
|
| 80 |
link.click();
|
| 81 |
-
|
| 82 |
-
// Cleanup
|
| 83 |
-
document.body.removeChild(link);
|
| 84 |
window.URL.revokeObjectURL(url);
|
| 85 |
|
| 86 |
toast.success("Download started!");
|
|
|
|
| 18 |
} from "@/components/ui/dropdown-menu";
|
| 19 |
import { ProjectType } from "@/types";
|
| 20 |
import { toast } from "sonner";
|
| 21 |
+
import { api } from "@/lib/api";
|
| 22 |
|
| 23 |
// from-red-500 to-red-500
|
| 24 |
// from-yellow-500 to-yellow-500
|
|
|
|
| 49 |
const handleDownload = async () => {
|
| 50 |
try {
|
| 51 |
toast.info("Preparing download...");
|
| 52 |
+
const response = await api.get(`/me/projects/${project.name}/download`);
|
| 53 |
+
const data = response.data;
|
| 54 |
|
| 55 |
+
const blob = new Blob([data.zip], { type: "application/zip" });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
const url = window.URL.createObjectURL(blob);
|
| 57 |
const link = document.createElement("a");
|
| 58 |
link.href = url;
|
| 59 |
link.download = `${project.name.replace(/\//g, "-")}.zip`;
|
| 60 |
document.body.appendChild(link);
|
| 61 |
link.click();
|
|
|
|
|
|
|
|
|
|
| 62 |
window.URL.revokeObjectURL(url);
|
| 63 |
|
| 64 |
toast.success("Download started!");
|