Spaces:
Running
Running
authorization was missing
Browse files- components/my-projects/project-card.tsx +23 -4
- hooks/useAi.ts +1 -1
components/my-projects/project-card.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
| 18 |
} from "@/components/ui/dropdown-menu";
|
| 19 |
import { ProjectType } from "@/types";
|
| 20 |
import { toast } from "sonner";
|
| 21 |
-
import {
|
| 22 |
|
| 23 |
// from-red-500 to-red-500
|
| 24 |
// from-yellow-500 to-yellow-500
|
|
@@ -36,6 +36,7 @@ export function ProjectCard({
|
|
| 36 |
project: ProjectType;
|
| 37 |
onDelete: () => void;
|
| 38 |
}) {
|
|
|
|
| 39 |
const handleDelete = () => {
|
| 40 |
if (
|
| 41 |
confirm(
|
|
@@ -49,16 +50,34 @@ export function ProjectCard({
|
|
| 49 |
const handleDownload = async () => {
|
| 50 |
try {
|
| 51 |
toast.info("Preparing download...");
|
| 52 |
-
const response = await
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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!");
|
|
|
|
| 18 |
} from "@/components/ui/dropdown-menu";
|
| 19 |
import { ProjectType } from "@/types";
|
| 20 |
import { toast } from "sonner";
|
| 21 |
+
import { useUser } from "@/hooks/useUser";
|
| 22 |
|
| 23 |
// from-red-500 to-red-500
|
| 24 |
// from-yellow-500 to-yellow-500
|
|
|
|
| 36 |
project: ProjectType;
|
| 37 |
onDelete: () => void;
|
| 38 |
}) {
|
| 39 |
+
const { token } = useUser();
|
| 40 |
const handleDelete = () => {
|
| 41 |
if (
|
| 42 |
confirm(
|
|
|
|
| 50 |
const handleDownload = async () => {
|
| 51 |
try {
|
| 52 |
toast.info("Preparing download...");
|
| 53 |
+
const response = await fetch(
|
| 54 |
+
`/deepsite/api/me/projects/${project.name}/download`,
|
| 55 |
+
{
|
| 56 |
+
credentials: "include",
|
| 57 |
+
headers: {
|
| 58 |
+
Accept: "application/zip",
|
| 59 |
+
Authorization: `Bearer ${token}`,
|
| 60 |
+
},
|
| 61 |
+
}
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
if (!response.ok) {
|
| 65 |
+
const error = await response
|
| 66 |
+
.json()
|
| 67 |
+
.catch(() => ({ error: "Download failed" }));
|
| 68 |
+
toast.error(error.error || "Failed to download project");
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
const blob = await response.blob();
|
| 73 |
|
|
|
|
| 74 |
const url = window.URL.createObjectURL(blob);
|
| 75 |
const link = document.createElement("a");
|
| 76 |
link.href = url;
|
| 77 |
link.download = `${project.name.replace(/\//g, "-")}.zip`;
|
| 78 |
document.body.appendChild(link);
|
| 79 |
link.click();
|
| 80 |
+
document.body.removeChild(link);
|
| 81 |
window.URL.revokeObjectURL(url);
|
| 82 |
|
| 83 |
toast.success("Download started!");
|
hooks/useAi.ts
CHANGED
|
@@ -19,7 +19,7 @@ export const useAi = (onScrollToBottom?: () => void) => {
|
|
| 19 |
const [storageProvider, setStorageProvider] = useLocalStorage("provider", "auto");
|
| 20 |
const [storageModel, setStorageModel] = useLocalStorage("model", MODELS[0].value);
|
| 21 |
const router = useRouter();
|
| 22 |
-
const {
|
| 23 |
const streamingPagesRef = useRef<Set<string>>(new Set());
|
| 24 |
|
| 25 |
const { data: isAiWorking = false } = useQuery({
|
|
|
|
| 19 |
const [storageProvider, setStorageProvider] = useLocalStorage("provider", "auto");
|
| 20 |
const [storageModel, setStorageModel] = useLocalStorage("model", MODELS[0].value);
|
| 21 |
const router = useRouter();
|
| 22 |
+
const { token } = useUser();
|
| 23 |
const streamingPagesRef = useRef<Set<string>>(new Set());
|
| 24 |
|
| 25 |
const { data: isAiWorking = false } = useQuery({
|