enhanced server settings section

This commit is contained in:
2026-01-01 17:53:50 +01:00
parent d7ab08c022
commit 01ae038a8b
21 changed files with 540 additions and 418 deletions

View File

@@ -1,43 +1,53 @@
import {FastifyReply, FastifyRequest} from 'fastify';
import {getConfig, setConfig} from '../../shared/config';
import { FastifyReply, FastifyRequest } from 'fastify';
import { getConfig, setConfig } from '../../shared/config';
export async function getFullConfig(req: FastifyRequest, reply: FastifyReply) {
try {
return getConfig();
} catch (err) {
const { values, schema } = getConfig();
return { values, schema };
} catch {
return { error: "Error loading config" };
}
}
export async function getConfigSection(req: FastifyRequest<{ Params: { section: string } }>, reply: FastifyReply) {
export async function getConfigSection(
req: FastifyRequest<{ Params: { section: string } }>,
reply: FastifyReply
) {
try {
const { section } = req.params;
const config = getConfig();
const { values } = getConfig();
if (config[section] === undefined) {
if (values[section] === undefined) {
return { error: "Section not found" };
}
return { [section]: config[section] };
} catch (err) {
return { [section]: values[section] };
} catch {
return { error: "Error loading config section" };
}
}
export async function updateConfig(req: FastifyRequest<{ Body: any }>, reply: FastifyReply) {
export async function updateConfig(
req: FastifyRequest<{ Body: any }>,
reply: FastifyReply
) {
try {
return setConfig(req.body);
} catch (err) {
return setConfig(req.body); // schema nunca se toca
} catch {
return { error: "Error updating config" };
}
}
export async function updateConfigSection(req: FastifyRequest<{ Params: { section: string }, Body: any }>, reply: FastifyReply) {
export async function updateConfigSection(
req: FastifyRequest<{ Params: { section: string }, Body: any }>,
reply: FastifyReply
) {
try {
const { section } = req.params;
const updatedConfig = setConfig({ [section]: req.body });
return { [section]: updatedConfig[section] };
} catch (err) {
const updatedValues = setConfig({ [section]: req.body });
return { [section]: updatedValues[section] };
} catch {
return { error: "Error updating config section" };
}
}