UNPKG

@fdm-monster/server

Version:

FDM Monster is a bulk OctoPrint, Klipper, PrusaLink and BambuLab manager to set up, configure and monitor 3D printers. Our aim is to provide neat overview over your farm.

32 lines (31 loc) 1.34 kB
import { ForbiddenError } from "../exceptions/runtime.exceptions.js"; import { inject } from "awilix-express"; //#region src/middleware/global.middleware.ts const validateWizardCompleted = inject((configService, settingsStore, loggerFactory) => async (req, _res, next) => { const logger = loggerFactory(validateWizardCompleted.name); if (configService.isDemoMode() || !!settingsStore.getWizardSettings()?.wizardCompleted) { next(); return; } const allowedPaths = [ "/api/v2/first-time-setup/complete", "/api/v2/first-time-setup/validate", "/api/v2/first-time-setup/yaml-import", "/api/v2/test", "/api/v2/auth/login-required" ]; if (allowedPaths.includes(req.path) || !req.path.startsWith("/api/v2") || req.path.startsWith("/api-docs")) next(); else { logger.error("Wizard not completed", req.path); throw new ForbiddenError(`First-time-setup not completed, these api paths are enabled: ${allowedPaths.join(", ")}`); } }); const interceptRoles = inject((settingsStore, roleService) => async (req, _res, next) => { const serverSettings = settingsStore.getSettings(); req.roles = req.user?.roles ?? []; if (serverSettings && !req.user) req.roles = await roleService.getAppDefaultRoleNames(); next(); }); //#endregion export { interceptRoles, validateWizardCompleted }; //# sourceMappingURL=global.middleware.js.map