All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m57s
28 lines
833 B
TypeScript
28 lines
833 B
TypeScript
import { prisma } from "@/lib/prisma";
|
|
import { normalizeBackgroundUrl } from "@/lib/avatars";
|
|
|
|
export async function getBackgroundImage(
|
|
page: "home" | "events" | "leaderboard",
|
|
defaultImage: string
|
|
): Promise<string> {
|
|
try {
|
|
const sitePreferences = await prisma.sitePreferences.findUnique({
|
|
where: { id: "global" },
|
|
});
|
|
|
|
if (!sitePreferences) {
|
|
return defaultImage;
|
|
}
|
|
|
|
const imageKey = `${page}Background` as keyof typeof sitePreferences;
|
|
const customImage = sitePreferences[imageKey];
|
|
|
|
const imageUrl = (customImage as string | null) || defaultImage;
|
|
// Normaliser l'URL pour utiliser l'API si nécessaire
|
|
return normalizeBackgroundUrl(imageUrl) || defaultImage;
|
|
} catch (error) {
|
|
console.error("Error fetching background image:", error);
|
|
return defaultImage;
|
|
}
|
|
}
|