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
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m57s
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user