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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user