diff --git a/src/app/_components/FileGrid.tsx b/src/app/_components/FileGrid.tsx index 892d032..78db341 100644 --- a/src/app/_components/FileGrid.tsx +++ b/src/app/_components/FileGrid.tsx @@ -39,7 +39,7 @@ export default function FileGrid({ session }: FileGridProps) { const handleDownload = async (fileName: string) => { try { - const response = await fetch(`/api/files/download?fileName=${encodeURIComponent(fileName)}`); + const response = await fetch(`/api/files/download?fileId=${encodeURIComponent(fileName)}`); if (!response.ok) { throw new Error("Failed to download file"); } diff --git a/src/app/api/files/download/route.ts b/src/app/api/files/download/route.ts index c9fe334..dbdb70d 100644 --- a/src/app/api/files/download/route.ts +++ b/src/app/api/files/download/route.ts @@ -4,7 +4,7 @@ import { promises as fs } from "fs"; export async function GET(req: Request) { const url = new URL(req.url); - const fileId = url.searchParams.get("fileName"); + const fileId = url.searchParams.get("fileId"); if (!fileId) { return NextResponse.json({ error: "File id is required" }, { status: 400 }); diff --git a/src/app/share/page.tsx b/src/app/share/page.tsx index c321cef..0751785 100644 --- a/src/app/share/page.tsx +++ b/src/app/share/page.tsx @@ -51,7 +51,11 @@ function UploadsPage() { const handleDownload = async () => { try { - const response = await fetch(`/api/files/download?fileId=${encodeURIComponent(fileDetails?.name ?? "")}`); // Use optional chaining + if (!fileDetails) { + toast.error("File details not available."); + return; + } + const response = await fetch(`/api/files/download?fileId=${encodeURIComponent(fileDetails?.name)}`); // Use optional chaining if (!response.ok) { throw new Error("Failed to download file"); }