All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m16s
Für jede Whitelist-Domain wird das Favicon jetzt einmalig geladen und im image-Verzeichnis abgelegt. SearchFilter zeigt das Icon neben dem Domain-Namen im Filter-Dropdown. - Migration 009: allowed_domain.favicon_path (NULL = noch nicht geladen). - Neues Modul $lib/server/domains/favicons.ts: fetchAndStoreFavicon(domain, imageDir) + ensureFavicons(db, imageDir) für Bulk-Nachzug; 8 parallele Worker mit 3s-Timeout. - Reihenfolge: erst /favicon.ico der Domain, Fallback Google-Service. - GET /api/domains zieht fehlende Favicons auf Abruf nach; POST /api/domains lädt direkt im selben Call. - .ico + .svg jetzt in der /images/[filename]-Route erlaubt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import type { RequestHandler } from './$types';
|
|
import { error } from '@sveltejs/kit';
|
|
import { createReadStream, existsSync, statSync } from 'node:fs';
|
|
import { join, basename, extname } from 'node:path';
|
|
|
|
const IMAGE_DIR = process.env.IMAGE_DIR ?? './data/images';
|
|
|
|
const MIME: Record<string, string> = {
|
|
'.jpg': 'image/jpeg',
|
|
'.jpeg': 'image/jpeg',
|
|
'.png': 'image/png',
|
|
'.webp': 'image/webp',
|
|
'.gif': 'image/gif',
|
|
'.avif': 'image/avif',
|
|
'.ico': 'image/x-icon',
|
|
'.svg': 'image/svg+xml'
|
|
};
|
|
|
|
export const GET: RequestHandler = ({ params }) => {
|
|
const filename = basename(params.filename ?? '');
|
|
if (!filename || filename.includes('..')) error(400, { message: 'Invalid filename' });
|
|
const full = join(IMAGE_DIR, filename);
|
|
if (!existsSync(full)) error(404, { message: 'Not found' });
|
|
|
|
const st = statSync(full);
|
|
const ext = extname(filename).toLowerCase();
|
|
const mime = MIME[ext] ?? 'application/octet-stream';
|
|
|
|
const stream = createReadStream(full);
|
|
return new Response(stream as unknown as ReadableStream, {
|
|
status: 200,
|
|
headers: {
|
|
'content-type': mime,
|
|
'content-length': String(st.size),
|
|
'cache-control': 'public, max-age=86400, immutable'
|
|
}
|
|
});
|
|
};
|