fix: Medien unabhaengig von Gross- und Kleinschreibung finden
Docker-Images bauen und veroeffentlichen / build-and-push (push) Successful in 2m53s

Im Container (Linux) wurde z. B. reels/Reel-1.JPG nicht als Vorschaubild
erkannt, weil nur exakt reel-1.jpg gesucht wurde. Die Suche vergleicht
Dateinamen jetzt ohne Ruecksicht auf die Schreibweise und liefert den
echten Dateinamen aus. Gilt fuer Logo, Headerbild, Portraets und Videos.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Opus 5.5 committed 2026-10-02 06:37:00 +02:00
1 parent a37f12a60f
commit bcf0f5c937
2 files changed
+24 -6

No files matched your search

+23 -5
View File
@@ -10,7 +10,7 @@
* Das Aenderungsdatum haengt als ?v=… an der URL: ein ersetztes Bild ist
* sofort sichtbar, obwohl /media/… einen Tag lang gecacht wird.
*/
import { stat } from "node:fs/promises";
import { readdir, stat } from "node:fs/promises";
import path from "node:path";
import { site, type Media } from "@/content/site";
import { env } from "./env";
@@ -21,14 +21,32 @@ const VIDEO_EXTS = [".mp4", ".webm"];
type Found = { src: string; ext: string };
/**
* Sucht "<ordner>/<name>.<endung>" ohne Ruecksicht auf Gross- und
* Kleinschreibung: Im Container (Linux) waere "Reel-1.JPG" sonst eine
* andere Datei als "reel-1.jpg". Geliefert wird der echte Dateiname.
*/
async function find(base: string, exts: readonly string[]): Promise<Found | null> {
const dir = path.resolve(env().MEDIA_DIR);
const root = path.resolve(env().MEDIA_DIR);
const folder = path.posix.dirname(base);
const name = path.posix.basename(base).toLowerCase();
const dir = folder === "." ? root : path.join(root, folder);
let entries: string[];
try {
entries = await readdir(dir);
} catch {
return null; // Ordner fehlt: Platzhalter bleibt.
}
for (const ext of exts) {
const match = entries.find((entry) => entry.toLowerCase() === `${name}${ext}`);
if (!match) continue;
try {
const info = await stat(path.join(dir, `${base}${ext}`));
if (info.isFile()) return { src: `/media/${base}${ext}?v=${Math.floor(info.mtimeMs)}`, ext };
const info = await stat(path.join(dir, match));
if (!info.isFile()) continue;
const rel = folder === "." ? match : `${folder}/${match}`;
return { src: `/media/${encodeURI(rel)}?v=${Math.floor(info.mtimeMs)}`, ext };
} catch {
// Datei fehlt: naechste Endung probieren.
// Datei zwischenzeitlich entfernt: naechste Endung probieren.
}
}
return null;