[refactor] string values to json

This commit is contained in:
Alireza Ahmadi
2024-06-06 22:07:26 +02:00
parent c994f4b24a
commit 2cabf0aefb
12 changed files with 121 additions and 138 deletions
+12 -12
View File
@@ -1,12 +1,13 @@
import { Link } from "@/plugins/link"
import RandomUtil from "@/plugins/randomUtil"
export interface Client {
id?: number
enable: boolean
name: string
config: string
inbounds: string
links: string
config: Config
inbounds: string[]
links: Link[]
volume: number
expiry: number
up: number
@@ -17,9 +18,9 @@ export interface Client {
const defaultClient: Client = {
enable: true,
name: "",
config: "[]",
inbounds: "",
links: "[]",
config: {},
inbounds: [],
links: [],
volume: 0,
expiry: 0,
up: 0,
@@ -35,12 +36,11 @@ type Config = {
}
}
export function updateConfigs(configs: string, newUserName: string): string {
const updatedConfigs: Config = JSON.parse(configs)
export function updateConfigs(configs: Config, newUserName: string): Config {
for (const key in updatedConfigs) {
if (updatedConfigs.hasOwnProperty(key)) {
const config = updatedConfigs[key]
for (const key in configs) {
if (configs.hasOwnProperty(key)) {
const config = configs[key]
if (config.hasOwnProperty("name")) {
config.name = newUserName
} else if (config.hasOwnProperty("username")) {
@@ -49,7 +49,7 @@ export function updateConfigs(configs: string, newUserName: string): string {
}
}
return JSON.stringify(updatedConfigs)
return configs
}
export function randomConfigs(user: string): Config {