fixed download link for share page

This commit is contained in:
ZareMate 2025-04-14 16:02:14 +02:00
parent 95392aa593
commit b4eb2b4657
Signed by: zaremate
GPG Key ID: 369A0E45E03A81C3
3 changed files with 7 additions and 3 deletions

View File

@ -39,7 +39,7 @@ export default function FileGrid({ session }: FileGridProps) {
const handleDownload = async (fileName: string) => { const handleDownload = async (fileName: string) => {
try { try {
const response = await fetch(`/api/files/download?fileName=${encodeURIComponent(fileName)}`); const response = await fetch(`/api/files/download?fileId=${encodeURIComponent(fileName)}`);
if (!response.ok) { if (!response.ok) {
throw new Error("Failed to download file"); throw new Error("Failed to download file");
} }

View File

@ -4,7 +4,7 @@ import { promises as fs } from "fs";
export async function GET(req: Request) { export async function GET(req: Request) {
const url = new URL(req.url); const url = new URL(req.url);
const fileId = url.searchParams.get("fileName"); const fileId = url.searchParams.get("fileId");
if (!fileId) { if (!fileId) {
return NextResponse.json({ error: "File id is required" }, { status: 400 }); return NextResponse.json({ error: "File id is required" }, { status: 400 });

View File

@ -51,7 +51,11 @@ function UploadsPage() {
const handleDownload = async () => { const handleDownload = async () => {
try { 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) { if (!response.ok) {
throw new Error("Failed to download file"); throw new Error("Failed to download file");
} }