Adding some methods in order to support the serving files images dynamically in production.

This commit is contained in:
charles-gauthereau
2025-01-12 14:03:15 +01:00
parent 2440592286
commit 7a59c616eb
5 changed files with 40 additions and 5 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import path from "path";
import * as fs from "node:fs";
import {getServerUrl} from "@/utils/get-server-url";
const privateLocalDir = "private/uploads/";
const privateLocalDir = "private/uploads/files/";
export async function uploadLocalPrivate(fileName: string, buffer: any) {
+3 -3
View File
@@ -55,7 +55,7 @@ function getUrl(fileName:string, settings: Settings, bucketName: string):string
return `https://${env.S3_ENDPOINT}/${bucketName}/${fileName}`
}else if(settings.storage === "local"){
const url = getServerUrl()
return `${url}/uploads/${fileName}`
return `${url}/api/images/${fileName}`
}
} else {
@@ -63,13 +63,13 @@ function getUrl(fileName:string, settings: Settings, bucketName: string):string
return `http://localhost:${env.S3_PORT}/${bucketName}/${fileName}`
}else if(settings.storage === "local"){
const url = getServerUrl()
return `${url}/uploads/${fileName}`
return `${url}/api/images/${fileName}`
}
}
}
async function uploadLocal(fileName: string, buffer: any) {
const localDir = "public/uploads/"
const localDir = "private/uploads/images/"
try {
await mkdir(path.join(process.cwd(), localDir), { recursive: true });
return await writeFile(