forked from fahrPool/fahrPool
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
export const LOGO_MAX_BYTES = 1024 * 1024;
|
|
|
|
export type LogoEndung = "png" | "jpg" | "svg";
|
|
|
|
const ENDUNG_NACH_TYP: Record<string, LogoEndung> = {
|
|
"image/png": "png",
|
|
"image/jpeg": "jpg",
|
|
"image/svg+xml": "svg",
|
|
};
|
|
|
|
const TYP_NACH_ENDUNG: Record<LogoEndung, string> = {
|
|
png: "image/png",
|
|
jpg: "image/jpeg",
|
|
svg: "image/svg+xml",
|
|
};
|
|
|
|
export function validateLogo(datei: { type: string; size: number }):
|
|
| { valid: true; endung: LogoEndung }
|
|
| { valid: false; error: string } {
|
|
if (datei.size === 0) return { valid: false, error: "Bitte eine Datei auswählen." };
|
|
const endung = ENDUNG_NACH_TYP[datei.type];
|
|
if (!endung) return { valid: false, error: "Bitte ein PNG-, JPG- oder SVG-Bild hochladen." };
|
|
if (datei.size > LOGO_MAX_BYTES) return { valid: false, error: "Das Logo darf höchstens 1 MB groß sein." };
|
|
return { valid: true, endung };
|
|
}
|
|
|
|
// Zeitstempel im Namen: ein neues Logo hat eine neue URL und kommt nicht aus dem Cache.
|
|
export function logoPfad(firmaId: string, endung: LogoEndung, jetzt: number = Date.now()): string {
|
|
return `${firmaId}/logo-${jetzt}.${endung}`;
|
|
}
|
|
|
|
export function logoContentType(pfad: string): string {
|
|
const endung = pfad.split(".").pop() as LogoEndung;
|
|
return TYP_NACH_ENDUNG[endung] ?? "application/octet-stream";
|
|
}
|
|
|
|
// Ein hochgeladenes SVG kann Script enthalten. Als <img> laeuft es nie, direkt
|
|
// geoeffnet verhindert die Sandbox-CSP die Ausfuehrung im App-Origin.
|
|
export const LOGO_SICHERHEITS_HEADER = {
|
|
"Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
|
|
"X-Content-Type-Options": "nosniff",
|
|
} as const;
|