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";
interface IUSettings {
export interface IUSettings {
keyrooms: string[];
rooms: string[];
cleanThings: string[];
@@ -24,7 +26,7 @@ class UOptions {
return this._settings;
}
public set settings(value: IUSettings) {
this._settings = value;
this._settings = project<typeof value>(value, ['cleanThings', 'keyrooms', 'menu', 'rooms', 'security']) as typeof value
this.save()
}

View File

@@ -1,5 +1,5 @@
import { Router } from "express";
import { adminPerm, Perms, project } from "@/utility";
import { adminPerm, Perms } from "@/utility";
import usettings from "@/helpers/usettings";
export const settingsRouter = Router()
@@ -11,7 +11,7 @@ settingsRouter.get('/', (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})
})

View File

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