All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m57s
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
/**
|
|
* Normalise une URL d'avatar pour utiliser la route API
|
|
* Gère la compatibilité avec les anciennes URLs directes
|
|
*/
|
|
export function normalizeAvatarUrl(
|
|
avatarUrl: string | null | undefined
|
|
): string | null {
|
|
if (!avatarUrl) {
|
|
return null;
|
|
}
|
|
|
|
// Si c'est déjà une URL API, la retourner telle quelle
|
|
if (avatarUrl.startsWith("/api/avatars/")) {
|
|
return avatarUrl;
|
|
}
|
|
|
|
// Si c'est une ancienne URL directe, la convertir en URL API
|
|
if (avatarUrl.startsWith("/uploads/avatars/")) {
|
|
const filename = avatarUrl.replace("/uploads/avatars/", "");
|
|
return `/api/avatars/${filename}`;
|
|
}
|
|
|
|
// Si c'est une URL complète (http/https) ou un chemin relatif autre, la retourner telle quelle
|
|
// (pour les avatars par défaut comme /avatar-1.jpg)
|
|
return avatarUrl;
|
|
}
|
|
|
|
/**
|
|
* Normalise une URL d'image de fond pour utiliser la route API
|
|
* Gère la compatibilité avec les anciennes URLs directes
|
|
*/
|
|
export function normalizeBackgroundUrl(
|
|
backgroundUrl: string | null | undefined
|
|
): string | null {
|
|
if (!backgroundUrl) {
|
|
return null;
|
|
}
|
|
|
|
// Si c'est déjà une URL API, la retourner telle quelle
|
|
if (backgroundUrl.startsWith("/api/backgrounds/")) {
|
|
return backgroundUrl;
|
|
}
|
|
|
|
// Si c'est une ancienne URL directe, la convertir en URL API
|
|
if (backgroundUrl.startsWith("/uploads/backgrounds/")) {
|
|
const filename = backgroundUrl.replace("/uploads/backgrounds/", "");
|
|
return `/api/backgrounds/${filename}`;
|
|
}
|
|
|
|
// Si c'est une URL complète (http/https) ou un chemin relatif autre, la retourner telle quelle
|
|
// (pour les images par défaut comme /got-2.jpg)
|
|
return backgroundUrl;
|
|
}
|