x3ui-api 1.0.7-1 → 1.0.8-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/package.json +1 -1
- package/src/core/X3UIClient.js +13 -19
- package/src/index.d.ts +0 -1
package/README.md
CHANGED
|
@@ -29,8 +29,7 @@ const X3UIClient = require('x3ui-api');
|
|
|
29
29
|
|
|
30
30
|
// Initialize client
|
|
31
31
|
const client = new X3UIClient({
|
|
32
|
-
baseURL: 'http://your-x3ui-panel.com:54321'
|
|
33
|
-
parseJSONSettings: true // Default: true - automatically parse JSON settings
|
|
32
|
+
baseURL: 'http://your-x3ui-panel.com:54321'
|
|
34
33
|
});
|
|
35
34
|
|
|
36
35
|
// Login to panel
|
|
@@ -315,7 +314,6 @@ async function manageInbounds() {
|
|
|
315
314
|
new X3UIClient({
|
|
316
315
|
baseURL: string, // Required: URL to your x3ui panel
|
|
317
316
|
token?: string, // Optional: Authentication token (if already logged in)
|
|
318
|
-
parseJSONSettings?: boolean // Optional: Auto-parse JSON settings (default: true)
|
|
319
317
|
})
|
|
320
318
|
```
|
|
321
319
|
|
package/package.json
CHANGED
package/src/core/X3UIClient.js
CHANGED
|
@@ -7,7 +7,6 @@ module.exports = class X3UIClient {
|
|
|
7
7
|
|
|
8
8
|
constructor(config) {
|
|
9
9
|
this.config = config;
|
|
10
|
-
this.config.parseJSONSettings ??= true;
|
|
11
10
|
this.client = axios.create({
|
|
12
11
|
baseURL: config.baseURL,
|
|
13
12
|
headers: config.token ? {
|
|
@@ -44,7 +43,7 @@ module.exports = class X3UIClient {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
async getSystemStats() {
|
|
47
|
-
if(!this.isAuthed) {
|
|
46
|
+
if (!this.isAuthed) {
|
|
48
47
|
await this.login();
|
|
49
48
|
}
|
|
50
49
|
const response = await this.client.post('/server/status');
|
|
@@ -70,24 +69,19 @@ module.exports = class X3UIClient {
|
|
|
70
69
|
* }>>}
|
|
71
70
|
*/
|
|
72
71
|
async getInbounds() {
|
|
73
|
-
if(!this.isAuthed) {
|
|
72
|
+
if (!this.isAuthed) {
|
|
74
73
|
await this.login();
|
|
75
74
|
}
|
|
76
75
|
const response = await this.client.get('/panel/api/inbounds/list');
|
|
77
76
|
let inbounds = response.data.obj;
|
|
78
|
-
|
|
79
|
-
inbounds = inbounds.map(inbound => this.parseInbound(inbound));
|
|
80
|
-
}
|
|
81
|
-
return inbounds;
|
|
77
|
+
return inbounds.map(inbound => this.parseInbound(inbound));
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
parseInbound(inbound) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
inbound.allocate = inbound.allocate && inbound.allocate.length > 0 ? JSON.parse(inbound.allocate) : {};
|
|
90
|
-
}
|
|
81
|
+
inbound.settings = inbound.settings && inbound.settings.length > 0 ? JSON.parse(inbound.settings) : {};
|
|
82
|
+
inbound.streamSettings = inbound.streamSettings && inbound.streamSettings.length > 0 ? JSON.parse(inbound.streamSettings) : {};
|
|
83
|
+
inbound.sniffing = inbound.sniffing && inbound.sniffing.length > 0 ? JSON.parse(inbound.sniffing) : {};
|
|
84
|
+
inbound.allocate = inbound.allocate && inbound.allocate.length > 0 ? JSON.parse(inbound.allocate) : {};
|
|
91
85
|
return inbound;
|
|
92
86
|
}
|
|
93
87
|
|
|
@@ -118,12 +112,12 @@ module.exports = class X3UIClient {
|
|
|
118
112
|
* @returns {Promise<void>}
|
|
119
113
|
*/
|
|
120
114
|
async addInbound(config) {
|
|
121
|
-
if(!this.isAuthed) {
|
|
115
|
+
if (!this.isAuthed) {
|
|
122
116
|
await this.login();
|
|
123
117
|
}
|
|
124
118
|
config = this.stringifyInbound(config);
|
|
125
119
|
const response = await this.client.post('/panel/api/inbounds/add', config);
|
|
126
|
-
if(!response.data.success)
|
|
120
|
+
if (!response.data.success)
|
|
127
121
|
throw new Error(response.data.msg);
|
|
128
122
|
return this.parseInbound(response.data.obj);
|
|
129
123
|
}
|
|
@@ -135,12 +129,12 @@ module.exports = class X3UIClient {
|
|
|
135
129
|
* @returns {Promise<void>}
|
|
136
130
|
*/
|
|
137
131
|
async updateInbound(id, config) {
|
|
138
|
-
if(!this.isAuthed) {
|
|
132
|
+
if (!this.isAuthed) {
|
|
139
133
|
await this.login();
|
|
140
134
|
}
|
|
141
135
|
config = this.stringifyInbound(config);
|
|
142
136
|
const response = await this.client.post(`/panel/api/inbounds/update/${id}`, config);
|
|
143
|
-
if(!response.data.success)
|
|
137
|
+
if (!response.data.success)
|
|
144
138
|
throw new Error(response.data.msg);
|
|
145
139
|
return this.parseInbound(response.data.obj);
|
|
146
140
|
}
|
|
@@ -151,7 +145,7 @@ module.exports = class X3UIClient {
|
|
|
151
145
|
* @returns {Promise<void>}
|
|
152
146
|
*/
|
|
153
147
|
async deleteInbound(id) {
|
|
154
|
-
if(!this.isAuthed) {
|
|
148
|
+
if (!this.isAuthed) {
|
|
155
149
|
await this.login();
|
|
156
150
|
}
|
|
157
151
|
await this.client.post(`/panel/api/inbounds/del/${id}`);
|
|
@@ -162,7 +156,7 @@ module.exports = class X3UIClient {
|
|
|
162
156
|
* @returns {Promise<{privateKey: string, publicKey: string}>} New X25519 key pair
|
|
163
157
|
*/
|
|
164
158
|
async getNewX25519Cert() {
|
|
165
|
-
if(!this.isAuthed) {
|
|
159
|
+
if (!this.isAuthed) {
|
|
166
160
|
await this.login();
|
|
167
161
|
}
|
|
168
162
|
const response = await this.client.post('/server/getNewX25519Cert');
|