From 1679eb5f33130f0f0d1647a97bdc711ac0fa3d02 Mon Sep 17 00:00:00 2001 From: Nico Prananta Date: Tue, 21 Nov 2023 22:05:57 +0100 Subject: [PATCH] use async --- app/api/download/[file_name]/route.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/api/download/[file_name]/route.ts b/app/api/download/[file_name]/route.ts index 4bc0d6f..6b5b112 100644 --- a/app/api/download/[file_name]/route.ts +++ b/app/api/download/[file_name]/route.ts @@ -13,11 +13,12 @@ export const GET = async ( const filePath = path.join(process.cwd(), `./files/${decodedFileName}`); try { - fs.accessSync(filePath, fs.constants.R_OK); + await fs.promises.access(filePath, fs.constants.R_OK); } catch (err: any) { if (err.code === "ENOENT") { return new Response("File not found", { status: 404 }); } else { + console.error(err); // Handle other possible errors (e.g., permission issues) return new Response("Error accessing file", { status: 500 }); }