feat: Added menu items and account security to settings

This commit is contained in:
2025-06-01 21:48:49 +02:00
parent df745c78e2
commit d50aa79c5d
3 changed files with 17 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
import { project } from "@/utility";
import { readFileSync, writeFileSync } from "node:fs"; import { readFileSync, writeFileSync } from "node:fs";
interface IUSettings {
export interface IUSettings {
keyrooms: string[]; keyrooms: string[];
rooms: string[]; rooms: string[];
cleanThings: string[]; cleanThings: string[];
@@ -24,7 +26,7 @@ class UOptions {
return this._settings; return this._settings;
} }
public set settings(value: IUSettings) { public set settings(value: IUSettings) {
this._settings = value; this._settings = project<typeof value>(value, ['cleanThings', 'keyrooms', 'menu', 'rooms', 'security']) as typeof value
this.save() this.save()
} }

View File

@@ -1,5 +1,5 @@
import { Router } from "express"; import { Router } from "express";
import { adminPerm, Perms, project } from "@/utility"; import { adminPerm, Perms } from "@/utility";
import usettings from "@/helpers/usettings"; import usettings from "@/helpers/usettings";
export const settingsRouter = Router() export const settingsRouter = Router()
@@ -11,7 +11,7 @@ settingsRouter.get('/', (req, res) => {
}) })
settingsRouter.post('/', (req, res) => { settingsRouter.post('/', (req, res) => {
usettings.settings = project(req.body, {keyrooms: true, cleanThings: true, rooms: true, menu: true, security: true}) usettings.settings = req.body
res.send({status: 200}) res.send({status: 200})
}) })

View File

@@ -38,12 +38,18 @@ var adminCond = (adminInt = 0, perm: Perms) => {
return (adminInt & perm) == perm return (adminInt & perm) == perm
} }
var project = (obj: any, projection: any) => { export function project<T extends object>(obj: T | any, projection: (keyof T)[] | { [key in keyof T]: any}): Partial<T> {
let obj2: any = {} let obj2: Partial<T> = {}
for (let key in projection) { if (projection instanceof Array) {
if (key in obj) obj2[key] = obj[key] for (let key of projection) {
if (key in obj) obj2[key] = obj[key]
}
} else {
for (let key in projection) {
if (key in obj) obj2[key] = obj[key]
}
} }
return obj2 return obj2
} }
export {islogged, isadmin, adminPerm, Perms, adminCond, project}; export {islogged, isadmin, adminPerm, Perms, adminCond};