Files
aidio-description/dist/server/routes/config.js
2026-05-15 04:10:06 +02:00

55 lines
2.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = require("express");
const jobStore_1 = require("../db/jobStore");
const config_1 = require("../../config/config");
const router = (0, express_1.Router)();
// Optional .env overrides for the (long) prompt strings — keep getDefaultConfig()'s
// hardcoded prompts as the final fallback. Users who want to tweak prompts without
// editing source can set these in .env, or set them per-job in the Settings UI.
const ENV_OVERRIDES = {
defaultPrompt: process.env.AIDIO_DEFAULT_PROMPT,
changePrompt: process.env.AIDIO_CHANGE_PROMPT,
batchPrompt: process.env.AIDIO_BATCH_PROMPT,
};
// Fields in Config that are nested objects (provider configs, etc.) and shouldn't
// be flattened into the form-facing config map. API keys live inside these — keep
// them off the wire.
const NESTED_FIELDS = new Set(['visionProviders', 'ttsProviders']);
function buildLayeredConfig() {
const defaults = (0, config_1.getDefaultConfig)();
const db = (0, jobStore_1.getAllConfig)();
const merged = {};
for (const [key, value] of Object.entries(defaults)) {
if (NESTED_FIELDS.has(key))
continue;
if (value === undefined || value === null)
continue;
merged[key] = String(value);
}
for (const [key, value] of Object.entries(ENV_OVERRIDES)) {
if (value !== undefined && value !== '')
merged[key] = value;
}
for (const [key, value] of Object.entries(db)) {
if (value !== undefined && value !== '')
merged[key] = value;
}
return merged;
}
router.get('/', (_req, res) => {
res.json({ config: buildLayeredConfig() });
});
router.put('/', (req, res) => {
const updates = req.body;
if (typeof updates !== 'object' || updates === null) {
res.status(400).json({ error: 'Body must be a JSON object of key-value pairs' });
return;
}
for (const [key, value] of Object.entries(updates)) {
(0, jobStore_1.setConfigValue)(key, String(value));
}
res.json({ config: buildLayeredConfig() });
});
exports.default = router;
//# sourceMappingURL=config.js.map