Werkstatt-App: öffentliche PWA und Redaktions-Backend
Werbefreie, barrierearme Info-App für Werkstätten (WfbM) auf Basis von SvelteKit, Tailwind, SQLite/Drizzle: - App: Startseite mit Kacheln, Meldungen, Seitenbaum, Termine inkl. Schließzeiten und iCal-Abo, Ansprechpartner, Suche, Kontaktformular, Merkliste, Vorlesen, Leichte Sprache, Schriftgrößen, Hell/Dunkel, PWA - Redaktion: Dashboard, Meldungen, Seiten, Termine, Kacheln, Ansprechpartner, Mediathek mit Bildoptimierung, Postfach, Benutzer mit Rollen, Einstellungen (Name, Logo, Farbe, Rechtstexte) - Demo-Seed, CLI zum Anlegen von Benutzern, Dockerfile und Compose Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4f145116d8
commit
bef8574e07
143 changed files with 13518 additions and 1 deletions
46
src/routes/app-icon/[size]/+server.ts
Normal file
46
src/routes/app-icon/[size]/+server.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import path from 'node:path';
|
||||
import sharp from 'sharp';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { getSettings } from '$lib/server/settings';
|
||||
import { db } from '$lib/server/db';
|
||||
import { media } from '$lib/server/db/schema';
|
||||
import { UPLOAD_DIR } from '$lib/server/env';
|
||||
|
||||
const cache = new Map<string, Buffer>();
|
||||
|
||||
/** App-Symbol: Logo auf weißem Grund, oder Anfangsbuchstabe auf Markenfarbe. */
|
||||
export const GET = async ({ params, url }) => {
|
||||
const size = Number(params.size);
|
||||
if (![32, 64, 180, 192, 512].includes(size)) error(404);
|
||||
const s = getSettings();
|
||||
const maskable = url.searchParams.has('maskable');
|
||||
const key = `${size}|${maskable}|${s.logoId}|${s.brandColor}|${s.appName}`;
|
||||
|
||||
let png = cache.get(key);
|
||||
if (!png) {
|
||||
const logo = s.logoId ? db.select().from(media).where(eq(media.id, s.logoId)).get() : undefined;
|
||||
if (logo?.mimeType.startsWith('image/')) {
|
||||
const inner = Math.round(size * (maskable ? 0.62 : 0.8));
|
||||
const img = await sharp(path.join(UPLOAD_DIR, logo.filename))
|
||||
.resize(inner, inner, { fit: 'contain', background: '#ffffff00' })
|
||||
.toBuffer();
|
||||
png = await sharp({ create: { width: size, height: size, channels: 4, background: '#ffffff' } })
|
||||
.composite([{ input: img, gravity: 'centre' }])
|
||||
.png()
|
||||
.toBuffer();
|
||||
} else {
|
||||
const letter = (s.appName.trim()[0] ?? 'W').toUpperCase().replace(/[<>&"']/g, '');
|
||||
const r = maskable ? 0 : size * 0.22;
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}">
|
||||
<rect width="100%" height="100%" rx="${r}" fill="${s.brandColor}"/>
|
||||
<text x="50%" y="52%" dominant-baseline="middle" text-anchor="middle" font-family="sans-serif" font-weight="700"
|
||||
font-size="${size * (maskable ? 0.42 : 0.56)}" fill="#ffffff">${letter}</text></svg>`;
|
||||
png = await sharp(Buffer.from(svg)).png().toBuffer();
|
||||
}
|
||||
cache.set(key, png);
|
||||
}
|
||||
return new Response(new Uint8Array(png), {
|
||||
headers: { 'Content-Type': 'image/png', 'Cache-Control': 'public, max-age=86400' }
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue