24 lines
943 B
JavaScript
24 lines
943 B
JavaScript
import { Router } from 'express';
|
|
import { z } from 'zod';
|
|
import { validate } from '../validate.js';
|
|
import { asyncWrap } from '../errors.js';
|
|
import { requireOwner } from '../cap.js';
|
|
import * as settings from '../../db/repos/app_settings.js';
|
|
|
|
const DEFAULT_SETTINGS = { avatar: 'soft-eye', accent: '#a86adf', persona: '', voiceMode: 'review' };
|
|
|
|
export const router = Router();
|
|
|
|
async function getCfg() { return { ...DEFAULT_SETTINGS, ...(await settings.get('dross', {})) }; }
|
|
|
|
router.get('/settings', asyncWrap(async (_req, res) => res.json(await getCfg())));
|
|
|
|
const settingsBody = z.object({
|
|
avatar: z.enum(['soft-eye', 'wisp', 'motes']),
|
|
accent: z.string().regex(/^#[0-9a-fA-F]{6}$/),
|
|
persona: z.string().max(8000),
|
|
voiceMode: z.enum(['review', 'handsfree', 'action'])
|
|
});
|
|
router.put('/settings', requireOwner, validate({ body: settingsBody }),
|
|
asyncWrap(async (req, res) => res.json(await settings.set('dross', req.body))));
|