Working on the API route for upload and the ping. adding types for actions.

This commit is contained in:
charles-gauthereau
2024-11-29 20:04:32 +01:00
parent e49a953852
commit bf4fce3a96
18 changed files with 283 additions and 30 deletions
+13 -7
View File
@@ -6,22 +6,28 @@ import {getServerUrl} from "@/utils/get-server-url";
const privateLocalDir = "private/uploads/";
async function uploadLocalPrivate(fileName: string, buffer: any) {
export async function uploadLocalPrivate(fileName: string, buffer: any) {
try {
await mkdir(path.join(process.cwd(), privateLocalDir), { recursive: true });
return await writeFile(
path.join(process.cwd(), privateLocalDir + fileName),
await writeFile(
path.join(process.cwd(), privateLocalDir, fileName),
buffer
)
);
return {
success: true,
message: "File uploaded successfully",
filePath: path.join(privateLocalDir, fileName),
};
} catch (error) {
console.log("Error occured ", error);
throw new Error('An error occured while importing private file');
console.error("Error occurred:", error);
throw new Error("An error occurred while importing the private file");
}
}
export async function getFileUrlPresignedLocal(fileName: string) {
try {
const filePath = path.join(privateLocalDir, fileName);