fix(settings, yjs, ux, ci): default settings, y-leveldb restart resilience, dashboard one-click open, delete error handling, Playwright CI

This commit is contained in:
2026-07-27 03:15:30 +02:00
parent 7f8695456c
commit 126277ab94
13 changed files with 129 additions and 45 deletions
+13 -2
View File
@@ -7,6 +7,13 @@ import { requireAuth } from '../auth/authMiddleware.js';
import type { AuthService } from '../auth/AuthService.js';
import { validateSettingsKey, validateSettingsValue } from '../utils/validation.js';
/** Built-in default settings so the frontend never sees a 404 for known keys. */
const DEFAULT_SETTINGS: Record<string, string> = {
'cad.unit': 'mm',
'cad.gridSize': '20',
'cad.scaleFactor': '1',
};
export function registerSettingsRoutes(fastify: FastifyInstance, db: DatabaseInterface, authService: AuthService) {
// Get a single setting by key
fastify.get('/api/settings/:key', async (request, reply) => {
@@ -15,8 +22,12 @@ export function registerSettingsRoutes(fastify: FastifyInstance, db: DatabaseInt
const keyErr = validateSettingsKey(key);
if (keyErr) return reply.code(400).send({ error: keyErr });
const setting = db.getSetting(key);
if (!setting) return reply.code(404).send({ error: 'Setting not found' });
return setting;
if (setting) return setting;
// Return a default value for known CAD settings instead of 404
if (DEFAULT_SETTINGS[key] !== undefined) {
return { key, value: DEFAULT_SETTINGS[key], updated_at: new Date().toISOString() };
}
return reply.code(404).send({ error: 'Setting not found' });
});
// Create or update a setting (upsert)