@fdm-monster/server
Version:
FDM Monster is a bulk OctoPrint manager to set up, configure and monitor 3D printers. Our aim is to provide extremely optimized websocket performance and reliability.
359 lines (358 loc) • 16.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "SettingsController", {
enumerable: true,
get: function() {
return SettingsController;
}
});
const _awilixexpress = require("awilix-express");
const _authenticate = require("../middleware/authenticate");
const _serverconstants = require("../server.constants");
const _authorizationconstants = require("../constants/authorization.constants");
const _validators = require("../handlers/validators");
const _settingsservicevalidation = require("../services/validators/settings-service.validation");
const _settingsstore = require("../state/settings.store");
const _express = require("express");
const _loggerfactory = require("../handlers/logger-factory");
const _demomiddleware = require("../middleware/demo.middleware");
const _printercache = require("../state/printer.cache");
const _printerapiinterface = require("../services/printer-api.interface");
const _printerserviceinterface = require("../services/interfaces/printer.service.interface");
const _printerthumbnailcache = require("../state/printer-thumbnail.cache");
const _settingvalidation = require("./validation/setting.validation");
function _ts_decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
}
class SettingsController {
serverVersion;
printerCache;
printerService;
settingsStore;
printerThumbnailCache;
logger;
constructor(loggerFactory, serverVersion, printerCache, printerService, settingsStore, printerThumbnailCache){
this.serverVersion = serverVersion;
this.printerCache = printerCache;
this.printerService = printerService;
this.settingsStore = settingsStore;
this.printerThumbnailCache = printerThumbnailCache;
this.logger = loggerFactory(SettingsController.name);
}
async getSettings(req, res) {
let connection;
try {
connection = {
clientIp: req.socket?.remoteAddress,
version: this.serverVersion
};
} catch (e) {
this.logger.warn("Could not fetch server IP address");
}
const settings = this.settingsStore.getSettings();
res.send({
...settings,
connection
});
}
async getSettingsSensitive(req, res) {
const settings = this.settingsStore.getSettingsSensitive();
res.send(settings);
}
async updateSentryDiagnosticsEnabled(req, res) {
const { enabled } = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.sentryDiagnosticsEnabledSchema);
const result = this.settingsStore.setSentryDiagnosticsEnabled(enabled);
res.send(result);
}
async updateMoonrakerSupport(req, res) {
const { enabled } = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.moonrakerSupportSchema);
const result = await this.settingsStore.setExperimentalMoonrakerSupport(enabled);
if (!enabled) {
const printers = await this.printerCache.listCachedPrinters(false);
const klipperPrinters = printers.filter((p)=>p.printerType === _printerapiinterface.MoonrakerType);
for (const printer of klipperPrinters){
await this.printerService.updateEnabled(printer.id, false);
}
}
res.send(result);
}
async updatePrusaLinkSupport(req, res) {
const { enabled } = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.prusaLinkSupportSchema);
const result = await this.settingsStore.setExperimentalPrusaLinkSupport(enabled);
if (!enabled) {
const printers = await this.printerCache.listCachedPrinters(false);
const prusaLinkPrinters = printers.filter((p)=>p.printerType === _printerapiinterface.PrusaLinkType);
for (const printer of prusaLinkPrinters){
await this.printerService.updateEnabled(printer.id, false);
}
}
res.send(result);
}
async updateThumbnailSupport(req, res) {
const { enabled } = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.thumbnailSupportSchema);
const result = await this.settingsStore.setExperimentalThumbnailSupport(enabled);
if (enabled) {
await this.printerThumbnailCache.loadCache();
} else {
await this.printerThumbnailCache.resetCache();
}
res.send(result);
}
async updateClientSupport(req, res) {
const { enabled } = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.clientNextSchema);
const result = await this.settingsStore.setExperimentalClientSupport(enabled);
res.send(result);
}
async updateFrontendSettings(req, res) {
const validatedInput = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.frontendSettingsUpdateSchema);
const result = await this.settingsStore.updateFrontendSettings(validatedInput);
res.send(result);
}
async updateLoginRequiredSettings(req, res) {
const { loginRequired } = await (0, _validators.validateInput)(req.body, _settingvalidation.loginRequiredSchema);
const result = await this.settingsStore.setLoginRequired(loginRequired);
res.send(result);
}
async updateRegistrationEnabledSettings(req, res) {
const { registrationEnabled } = await (0, _validators.validateInput)(req.body, _settingvalidation.registrationEnabledSchema);
const result = await this.settingsStore.setRegistrationEnabled(registrationEnabled);
res.send(result);
}
async updateCredentialSettings(req, res) {
const validatedInput = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.credentialSettingUpdateSchema);
await this.settingsStore.updateCredentialSettings(validatedInput);
res.send();
}
async updateFileCleanSettings(req, res) {
const validatedInput = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.fileCleanSettingsUpdateSchema);
const result = await this.settingsStore.updateFileCleanSettings(validatedInput);
res.send(result);
}
async updateTimeoutSettings(req, res) {
const validatedInput = await (0, _validators.validateInput)(req.body, _settingsservicevalidation.timeoutSettingsUpdateSchema);
const result = await this.settingsStore.updateTimeoutSettings(validatedInput);
res.send(result);
}
}
_ts_decorate([
(0, _awilixexpress.GET)(),
(0, _awilixexpress.route)("/"),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "getSettings", null);
_ts_decorate([
(0, _awilixexpress.GET)(),
(0, _awilixexpress.route)("/sensitive"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "getSettingsSensitive", null);
_ts_decorate([
(0, _awilixexpress.PATCH)(),
(0, _awilixexpress.route)("/sentry-diagnostics"),
(0, _awilixexpress.before)([
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateSentryDiagnosticsEnabled", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/experimental-moonraker-support"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateMoonrakerSupport", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/experimental-prusa-link-support"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updatePrusaLinkSupport", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/experimental-thumbnail-support"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateThumbnailSupport", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/experimental-client-support"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateClientSupport", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/frontend"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
])
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateFrontendSettings", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/login-required"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateLoginRequiredSettings", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/registration-enabled"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateRegistrationEnabledSettings", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/credential"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateCredentialSettings", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/file-clean"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateFileCleanSettings", null);
_ts_decorate([
(0, _awilixexpress.PUT)(),
(0, _awilixexpress.route)("/timeout"),
(0, _awilixexpress.before)([
(0, _authenticate.authorizeRoles)([
_authorizationconstants.ROLES.ADMIN
]),
_demomiddleware.demoUserNotAllowed
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _express.Request === "undefined" ? Object : _express.Request,
typeof _express.Response === "undefined" ? Object : _express.Response
]),
_ts_metadata("design:returntype", Promise)
], SettingsController.prototype, "updateTimeoutSettings", null);
SettingsController = _ts_decorate([
(0, _awilixexpress.route)(_serverconstants.AppConstants.apiRoute + "/settings"),
(0, _awilixexpress.before)([
(0, _authenticate.authenticate)()
]),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _loggerfactory.ILoggerFactory === "undefined" ? Object : _loggerfactory.ILoggerFactory,
String,
typeof _printercache.PrinterCache === "undefined" ? Object : _printercache.PrinterCache,
typeof _printerserviceinterface.IPrinterService === "undefined" ? Object : _printerserviceinterface.IPrinterService,
typeof _settingsstore.SettingsStore === "undefined" ? Object : _settingsstore.SettingsStore,
typeof _printerthumbnailcache.PrinterThumbnailCache === "undefined" ? Object : _printerthumbnailcache.PrinterThumbnailCache
])
], SettingsController);
//# sourceMappingURL=settings.controller.js.map