Refactor image URL handling: Update API routes to return image URLs via the API instead of direct paths, ensuring consistency across avatar and background uploads. Introduce normalization functions for avatar and background URLs to maintain compatibility with existing URLs.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m57s

This commit is contained in:
Julien Froidefond
2025-12-12 15:59:18 +01:00
parent 702476c349
commit f69fbbd0e1
11 changed files with 238 additions and 13 deletions

View File

@@ -57,8 +57,8 @@ export async function POST(request: Request) {
const buffer = Buffer.from(bytes);
await writeFile(filepath, buffer);
// Retourner l'URL de l'image
const imageUrl = `/uploads/avatars/${filename}`;
// Retourner l'URL de l'image via l'API
const imageUrl = `/api/avatars/${filename}`;
return NextResponse.json({ url: imageUrl });
} catch (error) {
console.error("Error uploading avatar:", error);

View File

@@ -26,7 +26,7 @@ export async function GET() {
(file) =>
file.match(/\.(jpg|jpeg|png|gif|webp|svg)$/i) && !file.startsWith(".")
);
images.push(...imageFiles.map((file) => `/uploads/backgrounds/${file}`));
images.push(...imageFiles.map((file) => `/api/backgrounds/${file}`));
}
return NextResponse.json({ images });

View File

@@ -48,8 +48,8 @@ export async function POST(request: Request) {
const buffer = Buffer.from(bytes);
await writeFile(filepath, buffer);
// Retourner l'URL de l'image
const imageUrl = `/uploads/backgrounds/${filename}`;
// Retourner l'URL de l'image via l'API
const imageUrl = `/api/backgrounds/${filename}`;
return NextResponse.json({ url: imageUrl });
} catch (error) {
console.error("Error uploading image:", error);