diff --git a/src/api.ts b/src/api.ts index e263d14..6469a05 100644 --- a/src/api.ts +++ b/src/api.ts @@ -9,6 +9,7 @@ import NodeCache from "node-cache"; import Axios from "axios"; import urlJoin from "url-join"; import qs from "qs"; +import { stringifySettings } from "$lib/utils/stringifySettings"; export class Api { readonly host: string; @@ -277,9 +278,9 @@ export class Api { this._logger.debug(`Adding inbound ${options.remark}.`); const inbound = await this.post("/add", { ...options, - settings: JSON.stringify(options.settings), - streamSettings: JSON.stringify(options.streamSettings), - sniffing: JSON.stringify(options.sniffing), + settings: stringifySettings(options.settings), + streamSettings: stringifySettings(options.streamSettings), + sniffing: stringifySettings(options.sniffing), }); this._logger.info(`Inbound ${inbound.remark} added.`); this.flushCache(); diff --git a/src/lib/utils/stringifySettings.ts b/src/lib/utils/stringifySettings.ts new file mode 100644 index 0000000..8dcac5f --- /dev/null +++ b/src/lib/utils/stringifySettings.ts @@ -0,0 +1,11 @@ +export const stringifySettings = (settings: any) => { + if (typeof settings === "object") { + return JSON.stringify(settings); + } + + if (typeof settings === "string") { + return settings; + } + + return ""; +}; diff --git a/tests/server.json b/tests/server.json index c624314..33e59cf 100644 --- a/tests/server.json +++ b/tests/server.json @@ -1,6 +1,6 @@ { - "username": "xBII1ZPkFx", - "password": "BZD8k3mWrm", - "port": "22642", - "webBasePath": "A63hQCOqreVqicR" + "username": "admin", + "password": "admin", + "port": "2053", + "webBasePath": "" }