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:
@@ -4,6 +4,14 @@ const path = require('path');
|
||||
const { LIMITS } = require('../../constants');
|
||||
const { exists } = require('../../fs-helpers');
|
||||
const { ValidationError } = require('../errors');
|
||||
/**
|
||||
* Config assets routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Object} deps.servicesStateManager - Services state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
|
||||
// Image processing for favicon conversion (optional)
|
||||
let sharp, pngToIco;
|
||||
@@ -14,12 +22,12 @@ try {
|
||||
// Image processing libraries not available — favicon conversion disabled
|
||||
}
|
||||
|
||||
module.exports = function(ctx) {
|
||||
module.exports = function({ servicesStateManager, asyncHandler, log }) {
|
||||
const router = express.Router();
|
||||
|
||||
// ===== ASSET UPLOAD =====
|
||||
|
||||
router.post('/assets/upload', express.json({ limit: LIMITS.BODY_UPLOAD }), ctx.asyncHandler(async (req, res) => {
|
||||
router.post('/assets/upload', express.json({ limit: LIMITS.BODY_UPLOAD }), asyncHandler(async (req, res) => {
|
||||
const { filename, data } = req.body;
|
||||
|
||||
if (!filename || !data) {
|
||||
@@ -65,7 +73,7 @@ module.exports = function(ctx) {
|
||||
// Manage custom dashboard logo
|
||||
|
||||
// Get current logo path, position, and title
|
||||
router.get('/logo', ctx.asyncHandler(async (req, res) => {
|
||||
router.get('/logo', asyncHandler(async (req, res) => {
|
||||
const config = await ctx.readConfig();
|
||||
res.json({
|
||||
success: true,
|
||||
@@ -100,7 +108,7 @@ module.exports = function(ctx) {
|
||||
|
||||
// Upload custom logo(s) and/or update position and title
|
||||
// Supports: dataDark/dataLight (separate variants) or data (single logo for both)
|
||||
router.post('/logo', express.json({ limit: LIMITS.BODY_UPLOAD }), ctx.asyncHandler(async (req, res) => {
|
||||
router.post('/logo', express.json({ limit: LIMITS.BODY_UPLOAD }), asyncHandler(async (req, res) => {
|
||||
const { data, dataDark, dataLight, position, dashboardTitle } = req.body;
|
||||
|
||||
if (!data && !dataDark && !dataLight && !position && !dashboardTitle) {
|
||||
@@ -159,7 +167,7 @@ module.exports = function(ctx) {
|
||||
}, 'logo-upload'));
|
||||
|
||||
// Reset all branding to defaults
|
||||
router.delete('/logo', ctx.asyncHandler(async (req, res) => {
|
||||
router.delete('/logo', asyncHandler(async (req, res) => {
|
||||
const config = await ctx.readConfig();
|
||||
const assetsPath = process.env.ASSETS_PATH || '/app/assets';
|
||||
|
||||
@@ -195,7 +203,7 @@ module.exports = function(ctx) {
|
||||
// Upload and convert favicon (PNG/SVG to ICO)
|
||||
|
||||
// Get current favicon
|
||||
router.get('/favicon', ctx.asyncHandler(async (req, res) => {
|
||||
router.get('/favicon', asyncHandler(async (req, res) => {
|
||||
const config = await ctx.readConfig();
|
||||
res.json({
|
||||
success: true,
|
||||
@@ -205,7 +213,7 @@ module.exports = function(ctx) {
|
||||
}, 'favicon-get'));
|
||||
|
||||
// Upload and convert favicon
|
||||
router.post('/favicon', ctx.asyncHandler(async (req, res) => {
|
||||
router.post('/favicon', asyncHandler(async (req, res) => {
|
||||
const { data } = req.body;
|
||||
|
||||
if (!data) {
|
||||
@@ -267,7 +275,7 @@ module.exports = function(ctx) {
|
||||
}, 'favicon'));
|
||||
|
||||
// Reset favicon to default
|
||||
router.delete('/favicon', ctx.asyncHandler(async (req, res) => {
|
||||
router.delete('/favicon', asyncHandler(async (req, res) => {
|
||||
const config = await ctx.readConfig();
|
||||
|
||||
// Delete custom favicon files
|
||||
|
||||
Reference in New Issue
Block a user