forked from fahrPool/fahrPool
fix: App-Icon-Route Fallback-Kette, Cache nur bei Erfolg, Schrift im Docker-Image
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
eb20d421b6
commit
befec482f9
|
|
@ -16,6 +16,8 @@ RUN npm run build
|
||||||
FROM node:22-alpine AS runner
|
FROM node:22-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
# Schrift fuer den Buchstaben im App-Icon (sharp/librsvg); alpine bringt keine mit.
|
||||||
|
RUN apk add --no-cache fontconfig font-dejavu
|
||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder /app/.next/standalone ./
|
COPY --from=builder /app/.next/standalone ./
|
||||||
COPY --from=builder /app/.next/static ./.next/static
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { createAdminClient } from "@/lib/supabase/admin";
|
||||||
import { STANDARD_FARBE_PRIMAER } from "@/lib/firma/farben";
|
import { STANDARD_FARBE_PRIMAER } from "@/lib/firma/farben";
|
||||||
import {
|
import {
|
||||||
iconBuchstabe,
|
iconBuchstabe,
|
||||||
iconQuelle,
|
|
||||||
parseIconAnfrage,
|
parseIconAnfrage,
|
||||||
renderAppIcon,
|
renderAppIcon,
|
||||||
type IconBranding,
|
type IconBranding,
|
||||||
|
|
@ -35,32 +34,38 @@ export async function GET(
|
||||||
}
|
}
|
||||||
|
|
||||||
const farbe = branding?.farbe_primaer ?? STANDARD_FARBE_PRIMAER;
|
const farbe = branding?.farbe_primaer ?? STANDARD_FARBE_PRIMAER;
|
||||||
const quelle = iconQuelle(branding);
|
|
||||||
const buchstabe = iconBuchstabe(branding);
|
const buchstabe = iconBuchstabe(branding);
|
||||||
|
|
||||||
|
// Fallback-Kette App-Icon -> Logo -> Buchstabe; bei Fehlern naechste Stufe.
|
||||||
|
const stufen: { art: "app-icon" | "logo"; pfad: string }[] = [];
|
||||||
|
if (branding?.app_icon_pfad) stufen.push({ art: "app-icon", pfad: branding.app_icon_pfad });
|
||||||
|
if (branding?.logo_pfad) stufen.push({ art: "logo", pfad: branding.logo_pfad });
|
||||||
|
|
||||||
let png: Buffer | null = null;
|
let png: Buffer | null = null;
|
||||||
if (admin && quelle.art !== "buchstabe") {
|
let fallback = false;
|
||||||
const { data, error } = await admin.storage.from("firmen-logos").download(quelle.pfad);
|
for (const stufe of stufen) {
|
||||||
if (!error && data) {
|
if (!admin) break;
|
||||||
try {
|
try {
|
||||||
png = await renderAppIcon({
|
const { data, error } = await admin.storage.from("firmen-logos").download(stufe.pfad);
|
||||||
quelle: Buffer.from(await data.arrayBuffer()),
|
if (error || !data) throw error ?? new Error("leer");
|
||||||
art: quelle.art,
|
png = await renderAppIcon({
|
||||||
farbe,
|
quelle: Buffer.from(await data.arrayBuffer()),
|
||||||
groesse: anfrage.groesse,
|
art: stufe.art,
|
||||||
});
|
farbe,
|
||||||
} catch {
|
groesse: anfrage.groesse,
|
||||||
// Unlesbare Quelldatei: wie ein Download-Fehler behandeln.
|
});
|
||||||
}
|
break;
|
||||||
|
} catch {
|
||||||
|
fallback = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Download-/Lesefehler oder kein Bild hinterlegt: Buchstabe auf Firmenfarbe.
|
|
||||||
png ??= await renderAppIcon({ quelle: null, art: "buchstabe", buchstabe, farbe, groesse: anfrage.groesse });
|
png ??= await renderAppIcon({ quelle: null, art: "buchstabe", buchstabe, farbe, groesse: anfrage.groesse });
|
||||||
|
|
||||||
return new Response(new Uint8Array(png), {
|
return new Response(new Uint8Array(png), {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "image/png",
|
"Content-Type": "image/png",
|
||||||
"Cache-Control": "public, max-age=31536000, immutable",
|
// Nach einem Fallback nicht ein Jahr festschreiben (z.B. voruebergehender Storage-Fehler).
|
||||||
|
"Cache-Control": fallback ? "no-store" : "public, max-age=31536000, immutable",
|
||||||
"X-Content-Type-Options": "nosniff",
|
"X-Content-Type-Options": "nosniff",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -114,4 +114,14 @@ describe("renderAppIcon", () => {
|
||||||
const data = await sharp(buf).raw().toBuffer();
|
const data = await sharp(buf).raw().toBuffer();
|
||||||
expect([data[0], data[1], data[2]]).toEqual([0x00, 0x71, 0xed]);
|
expect([data[0], data[1], data[2]]).toEqual([0x00, 0x71, 0xed]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Buchstaben-Icon hat Vordergrundpixel in der Mitte", async () => {
|
||||||
|
const buf = await renderAppIcon({ quelle: null, art: "buchstabe", buchstabe: "W", farbe: "#0071ed", groesse: "512" });
|
||||||
|
const mitte = await sharp(buf).extract({ left: 156, top: 156, width: 200, height: 200 }).raw().toBuffer();
|
||||||
|
let abweichend = 0;
|
||||||
|
for (let i = 0; i < mitte.length; i += 3) {
|
||||||
|
if (mitte[i] !== 0x00 || mitte[i + 1] !== 0x71 || mitte[i + 2] !== 0xed) abweichend++;
|
||||||
|
}
|
||||||
|
expect(abweichend).toBeGreaterThan(500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export function parseIconAnfrage(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function iconBuchstabe(f: IconBranding | null): string {
|
export function iconBuchstabe(f: IconBranding | null): string {
|
||||||
return (f?.name ?? "").trim().charAt(0).toUpperCase() || "A";
|
return [...(f?.name ?? "").trim()][0]?.toUpperCase() || "A";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function iconQuelle(
|
export function iconQuelle(
|
||||||
|
|
@ -66,7 +66,7 @@ function buchstabeSvg(buchstabe: string, n: number): Buffer {
|
||||||
return Buffer.from(
|
return Buffer.from(
|
||||||
`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${n}">` +
|
`<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${n}">` +
|
||||||
`<text x="50%" y="50%" dy="0.35em" text-anchor="middle" fill="${WEISS}" ` +
|
`<text x="50%" y="50%" dy="0.35em" text-anchor="middle" fill="${WEISS}" ` +
|
||||||
`font-family="Inter, Arial, Helvetica, sans-serif" font-weight="700" font-size="${Math.round(n * 0.6)}">${zeichen}</text></svg>`
|
`font-family="DejaVu Sans, Inter, Arial, sans-serif" font-weight="700" font-size="${Math.round(n * 0.6)}">${zeichen}</text></svg>`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue