Skip to content

Commit

Permalink
fix bugs with stringifying settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdikhody committed Oct 10, 2024
1 parent 2bac5dd commit 07eda2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -277,9 +278,9 @@ export class Api {
this._logger.debug(`Adding inbound ${options.remark}.`);
const inbound = await this.post<Inbound>("/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();
Expand Down
11 changes: 11 additions & 0 deletions src/lib/utils/stringifySettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const stringifySettings = (settings: any) => {
if (typeof settings === "object") {
return JSON.stringify(settings);
}

if (typeof settings === "string") {
return settings;
}

return "";
};
8 changes: 4 additions & 4 deletions tests/server.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"username": "xBII1ZPkFx",
"password": "BZD8k3mWrm",
"port": "22642",
"webBasePath": "A63hQCOqreVqicR"
"username": "admin",
"password": "admin",
"port": "2053",
"webBasePath": ""
}

0 comments on commit 07eda2d

Please sign in to comment.