build app logo

This commit is contained in:
2026-03-28 22:48:37 -05:00
parent b08e9523e4
commit 7fba3645c3
8 changed files with 186 additions and 10 deletions

View File

@@ -43,6 +43,11 @@ db.exec(`
name TEXT UNIQUE NOT NULL COLLATE NOCASE
);
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT
);
CREATE TABLE IF NOT EXISTS meme_tags (
meme_id TEXT NOT NULL REFERENCES memes(id) ON DELETE CASCADE,
tag_id INTEGER NOT NULL REFERENCES tags(id) ON DELETE CASCADE,

View File

@@ -10,6 +10,7 @@ import { authRoutes } from './routes/auth.js';
import { collectionsRoutes } from './routes/collections.js';
import { adminRoutes } from './routes/admin.js';
import { shareRoutes } from './routes/share.js';
import { settingsRoutes } from './routes/settings.js';
// Ensure data dirs exist
ensureImagesDir();
@@ -46,6 +47,7 @@ await app.register(tagsRoutes);
await app.register(adminRoutes);
await app.register(shareRoutes);
await app.register(settingsRoutes);
// SPA fallback — serve index.html for all non-API, non-image routes
app.setNotFoundHandler(async (req, reply) => {

View File

@@ -0,0 +1,38 @@
import type { FastifyInstance } from 'fastify';
import db from '../db.js';
import { requireAuth } from '../auth.js';
type SettingsRow = { key: string; value: string };
function getAllSettings(): Record<string, string> {
const rows = db.prepare('SELECT key, value FROM settings').all() as SettingsRow[];
return Object.fromEntries(rows.map((r) => [r.key, r.value]));
}
export async function settingsRoutes(app: FastifyInstance) {
// Public — anyone can read settings (needed to render logo for guests)
app.get('/api/settings', async () => {
return getAllSettings();
});
// Admin — update one or more settings keys
app.put<{ Body: Record<string, string> }>(
'/api/settings',
{ preHandler: requireAuth },
async (req) => {
const allowed = new Set(['logo_url']);
const stmt = db.prepare(
'INSERT INTO settings (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value'
);
for (const [key, value] of Object.entries(req.body)) {
if (!allowed.has(key)) continue;
if (value === '' || value == null) {
db.prepare('DELETE FROM settings WHERE key = ?').run(key);
} else {
stmt.run(key, String(value));
}
}
return getAllSettings();
}
);
}