Refactor config routes: explicit dependency injection
- Updated all config route modules to use destructured dependencies - Added JSDoc comments for factory functions - Replaced ctx. references with direct parameter access - All files pass syntax validation Files refactored: - routes/config/assets.js - routes/config/backup.js - routes/config/settings.js - routes/config/index.js (orchestrator)
This commit is contained in:
@@ -3,14 +3,22 @@ const { validateConfig } = require('../../config-schema');
|
||||
const { exists } = require('../../fs-helpers');
|
||||
const { ValidationError } = require('../errors');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
module.exports = function({ configStateManager, asyncHandler, log }) {
|
||||
/**
|
||||
* Config settings routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Object} deps.configStateManager - Config state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
// ===== DASHCADDY CONFIG ENDPOINTS =====
|
||||
// Server-side config storage for setup wizard (shared across all browsers/machines)
|
||||
|
||||
router.get('/config', ctx.asyncHandler(async (req, res) => {
|
||||
router.get('/config', asyncHandler(async (req, res) => {
|
||||
if (!await exists(ctx.CONFIG_FILE)) {
|
||||
return res.json({ setupComplete: false });
|
||||
}
|
||||
@@ -19,7 +27,7 @@ module.exports = function(ctx) {
|
||||
res.json(config);
|
||||
}, 'config-get'));
|
||||
|
||||
router.post('/config', ctx.asyncHandler(async (req, res) => {
|
||||
router.post('/config', asyncHandler(async (req, res) => {
|
||||
const incoming = req.body;
|
||||
|
||||
if (!incoming || typeof incoming !== 'object') {
|
||||
@@ -55,12 +63,12 @@ module.exports = function(ctx) {
|
||||
|
||||
await fsp.writeFile(ctx.CONFIG_FILE, JSON.stringify(config, null, 2), 'utf8');
|
||||
ctx.loadSiteConfig(); // Refresh in-memory config
|
||||
ctx.log.info('config', 'Config saved', { path: ctx.CONFIG_FILE });
|
||||
log.info('config', 'Config saved', { path: ctx.CONFIG_FILE });
|
||||
|
||||
res.json({ success: true, message: 'Configuration saved', config, warnings });
|
||||
}, 'config-save'));
|
||||
|
||||
router.delete('/config', ctx.asyncHandler(async (req, res) => {
|
||||
router.delete('/config', asyncHandler(async (req, res) => {
|
||||
if (await exists(ctx.CONFIG_FILE)) {
|
||||
await fsp.unlink(ctx.CONFIG_FILE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user