@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.
88 lines (87 loc) • 4.58 kB
JavaScript
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.129.0/helpers/decorateMetadata.js";
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.129.0/helpers/decorate.js";
import { BadRequestException, ForbiddenError } from "../exceptions/runtime.exceptions.js";
import { validateMiddleware } from "../handlers/validators.js";
import { AppConstants } from "../server.constants.js";
import { SettingsStore } from "../state/settings.store.js";
import { ROLES } from "../constants/authorization.constants.js";
import { MulterService } from "../services/core/multer.service.js";
import { wizardSettingsSchema } from "./validation/setting.validation.js";
import { YamlService } from "../services/core/yaml.service.js";
import { POST, route } from "awilix-express";
//#region src/controllers/first-time-setup.controller.ts
var first_time_setup_controller_exports = /* @__PURE__ */ __exportAll({ FirstTimeSetupController: () => FirstTimeSetupController });
var _ref, _ref2, _ref3;
let FirstTimeSetupController = class FirstTimeSetupController {
constructor(settingsStore, roleService, userService, yamlService, multerService) {
this.settingsStore = settingsStore;
this.roleService = roleService;
this.userService = userService;
this.yamlService = yamlService;
this.multerService = multerService;
}
async validateWizard(req, res) {
const { rootUsername } = await validateMiddleware(req, wizardSettingsSchema);
await this.roleService.getSynchronizedRoleByName(ROLES.ADMIN);
if (this.settingsStore.isWizardCompleted()) throw new ForbiddenError("Wizard already completed");
if (await this.userService.findRawByUsername(rootUsername?.toLowerCase())) throw new BadRequestException("This user already exists");
return res.send();
}
async completeWizard(req, res) {
const { loginRequired, registration, rootUsername, rootPassword } = await validateMiddleware(req, wizardSettingsSchema);
if (this.settingsStore.isWizardCompleted()) throw new ForbiddenError("Wizard already completed");
await this.roleService.getSynchronizedRoleByName(ROLES.ADMIN);
if (await this.userService.findRawByUsername(rootUsername?.toLowerCase())) throw new BadRequestException("This user already exists");
await this.userService.register({
username: rootUsername,
password: rootPassword,
roles: [ROLES.ADMIN],
isRootUser: true,
isVerified: true,
isDemoUser: false,
needsPasswordChange: false
});
await this.settingsStore.setLoginRequired(loginRequired);
await this.settingsStore.setRegistrationEnabled(registration);
await this.settingsStore.setWizardCompleted(AppConstants.currentWizardVersion);
return res.send();
}
async importYamlFile(req, res) {
if (this.settingsStore.isWizardCompleted()) throw new ForbiddenError("Wizard already completed. Cannot import during first-time setup once wizard is complete.");
const firstFile = (await this.multerService.multerLoadFileAsync(req, res, [".yaml", ".yml"], false))[0];
await this.yamlService.importYaml(firstFile.buffer.toString());
return res.send({ success: true });
}
};
__decorate([
POST(),
route("/validate"),
__decorateMetadata("design:type", Function),
__decorateMetadata("design:paramtypes", [Object, Object]),
__decorateMetadata("design:returntype", Promise)
], FirstTimeSetupController.prototype, "validateWizard", null);
__decorate([
POST(),
route("/complete"),
__decorateMetadata("design:type", Function),
__decorateMetadata("design:paramtypes", [Object, Object]),
__decorateMetadata("design:returntype", Promise)
], FirstTimeSetupController.prototype, "completeWizard", null);
__decorate([
POST(),
route("/yaml-import"),
__decorateMetadata("design:type", Function),
__decorateMetadata("design:paramtypes", [Object, Object]),
__decorateMetadata("design:returntype", Promise)
], FirstTimeSetupController.prototype, "importYamlFile", null);
FirstTimeSetupController = __decorate([route(AppConstants.apiRoute + "/first-time-setup"), __decorateMetadata("design:paramtypes", [
typeof (_ref = typeof SettingsStore !== "undefined" && SettingsStore) === "function" ? _ref : Object,
Object,
Object,
typeof (_ref2 = typeof YamlService !== "undefined" && YamlService) === "function" ? _ref2 : Object,
typeof (_ref3 = typeof MulterService !== "undefined" && MulterService) === "function" ? _ref3 : Object
])], FirstTimeSetupController);
//#endregion
export { FirstTimeSetupController, first_time_setup_controller_exports };
//# sourceMappingURL=first-time-setup.controller.js.map