Adversarial audit 2026-08-16 (GLM-5.3 delegate, 2 rounds, 141 tool calls):
P0-1: Dashboard WebSocket (/api/v1/ws) dead on EVERY boot since DC-076.
server.js passed module exports (DependencyManager class, {AutoRestartManager}
namespace, SSLMonitor class) instead of createApp()'s live instances — first
.on() threw ERR_INVALID_ARG_TYPE, catch swallowed it. Fix: app.locals.ctx
exposed in src/app.js; server.js passes all 8 real EventEmitter instances.
P0-2: error.log corrupted since 2026-07-14. errorMiddleware called
logError(FILE, SIZE, path, err, meta) — 5 args into a 3-arg wrapper —
logging 'Error: 5242880' garbage every ~60s and DISCARDING the real error
object. Fix: correct 3-arg call + legacy-shape guard in logErrorWrapper +
~74 log.error sites swept to pass real error objects (AST-verified scope-
safe 71/71, 29/29 modules load clean).
P0-3: auth-polling storm (stranded grade=B commit never landed in prod):
401/403 behind TOTP gate hammered /api/v1/services/status + SSE reconnect
every 2-8s, with misleading direct-probe fallback marking services 'up'.
Fix landed + B-round MEDIUM follow-up: TOTP re-auth success now clears
_dcAuthLost, resumes SSE (new _sseResume clears the latch), and refreshes.
Also: eslintignore static-sites/ (33→0 errors); nodemailer 8→9.0.5 and
sharp 0.33→0.35.3 (3 high CVEs killed; jest green on new majors);
dockerode@5/uuid deferred (semver-major, Docker API surface).
Verification: 80/80 suites, 1837/1837 tests; ESLint 0 errors/743 warnings;
node --check all changed files; bundles rebuilt + SW cache bumped.
Judges: Codex quota-dead until Aug 19 (verified live) — GLM adversarial
delegate per operator directive 2026-08-07. Round 1: 98-call mechanical
verification (timed out pre-verdict). Round 2 (this grade): B, one MEDIUM
(re-auth freeze) — fixed in this commit as prescribed.
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
const express = require('express');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { success } = require('../src/utils/responses');
|
|
const { ValidationError, NotFoundError } = require('../src/utilities/errors');
|
|
const platformPaths = require('../platform-paths');
|
|
|
|
/**
|
|
* Themes routes factory
|
|
* @param {Object} deps - Explicit dependencies
|
|
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
|
* @param {Object} deps.log - Logger instance
|
|
* @returns {express.Router}
|
|
*/
|
|
module.exports = function({ asyncHandler, log }) {
|
|
const router = express.Router();
|
|
const THEMES_DIR = process.env.THEMES_DIR || path.join(path.dirname(platformPaths.servicesFile), 'themes');
|
|
|
|
// Ensure themes directory exists
|
|
if (!fs.existsSync(THEMES_DIR)) {
|
|
fs.mkdirSync(THEMES_DIR, { recursive: true });
|
|
}
|
|
|
|
function readAllThemes() {
|
|
const themes = {};
|
|
try {
|
|
const files = fs.readdirSync(THEMES_DIR).filter(f => f.endsWith('.json'));
|
|
for (const file of files) {
|
|
const slug = path.basename(file, '.json');
|
|
const data = JSON.parse(fs.readFileSync(path.join(THEMES_DIR, file), 'utf8'));
|
|
themes[slug] = data;
|
|
}
|
|
} catch (e) {
|
|
log.error('themes', e, null, { note: 'Failed to read themes' });
|
|
}
|
|
return themes;
|
|
}
|
|
|
|
// Get all user themes
|
|
router.get('/themes', (req, res) => {
|
|
success(res, { themes: readAllThemes() });
|
|
});
|
|
|
|
// Save a theme (create or update)
|
|
router.post('/themes/:slug', asyncHandler(async (req, res) => {
|
|
const { slug } = req.params;
|
|
const { name, colors, lightBg } = req.body;
|
|
|
|
if (!slug || !name || !colors) {
|
|
throw new ValidationError('Missing slug, name, or colors');
|
|
}
|
|
|
|
if (!/^[a-z0-9-]+$/.test(slug)) {
|
|
throw new ValidationError('Invalid slug format (use lowercase letters, numbers, and hyphens only)', 'slug');
|
|
}
|
|
|
|
const themeData = { name, ...colors };
|
|
if (lightBg) themeData.lightBg = true;
|
|
fs.writeFileSync(path.join(THEMES_DIR, slug + '.json'), JSON.stringify(themeData, null, 2), 'utf8');
|
|
|
|
success(res, { message: name + ' theme saved' });
|
|
}));
|
|
|
|
// Delete a theme
|
|
router.delete('/themes/:slug', asyncHandler(async (req, res) => {
|
|
const { slug } = req.params;
|
|
const filePath = path.join(THEMES_DIR, slug + '.json');
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
throw new NotFoundError(`Theme ${slug}`);
|
|
}
|
|
|
|
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
const name = data.name || slug;
|
|
fs.unlinkSync(filePath);
|
|
|
|
success(res, { message: name + ' theme deleted' });
|
|
}));
|
|
|
|
return router;
|
|
};
|