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" };
}
}

View File

@@ -70,8 +70,8 @@ async function getOrCreateEntry(
throw new Error('METADATA_NOT_FOUND');
}
const config = loadConfig();
const basePath = config.library?.[type];
const { values } = loadConfig();
const basePath = values.library?.[type];
if (!basePath) {
throw new Error(`NO_LIBRARY_PATH_FOR_${type.toUpperCase()}`);

View File

@@ -127,9 +127,9 @@ export async function resolveEntryMetadata(entry: any, type: string) {
}
export async function performLibraryScan(mode: 'full' | 'incremental' = 'incremental') {
const config = loadConfig();
const { values } = loadConfig();
if (!config.library) {
if (!values.library) {
throw new Error('NO_LIBRARY_CONFIGURED');
}
@@ -138,7 +138,7 @@ export async function performLibraryScan(mode: 'full' | 'incremental' = 'increme
await run(`DELETE FROM local_entries`, [], 'local_library');
}
for (const [type, basePath] of Object.entries(config.library)) {
for (const [type, basePath] of Object.entries(values.library)) {
if (!basePath || !fs.existsSync(<PathLike>basePath)) continue;
const dirs = fs.readdirSync(<string>basePath, { withFileTypes: true }).filter(d => d.isDirectory());