x3ui-api 1.0.0 → 1.0.2
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/package.json +1 -1
- package/src/index.d.ts +17 -2
- package/src/index.js +43 -2
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -201,9 +201,17 @@ export interface ClientBuilder {
|
|
|
201
201
|
setTgId(id: string): this;
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
|
-
* Build client configuration
|
|
204
|
+
* Build the client configuration
|
|
205
205
|
*/
|
|
206
|
-
build():
|
|
206
|
+
build(): ClientSettings;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Generate connection link for this client
|
|
210
|
+
* @param host Host address
|
|
211
|
+
* @param port Optional port number, defaults to parent's port
|
|
212
|
+
* @param protocol Optional protocol, defaults to parent's protocol or 'vless'
|
|
213
|
+
*/
|
|
214
|
+
getLink(host: string, port?: number, protocol?: string): string;
|
|
207
215
|
}
|
|
208
216
|
|
|
209
217
|
export interface RealityBuilder {
|
|
@@ -257,6 +265,13 @@ export interface RealityBuilder {
|
|
|
257
265
|
*/
|
|
258
266
|
addClient(options?: Partial<ClientSettings>): ClientBuilder;
|
|
259
267
|
|
|
268
|
+
/**
|
|
269
|
+
* Get connection link for a client
|
|
270
|
+
* @param clientIndex Index of the client (defaults to 0)
|
|
271
|
+
* @param host Optional host address (defaults to listenIP or 'localhost')
|
|
272
|
+
*/
|
|
273
|
+
getClientLink(clientIndex?: number, host?: string): string;
|
|
274
|
+
|
|
260
275
|
/**
|
|
261
276
|
* Build the final inbound config
|
|
262
277
|
*/
|
package/src/index.js
CHANGED
|
@@ -75,7 +75,7 @@ module.exports = class X3UIClient {
|
|
|
75
75
|
inbound.settings = JSON.parse(inbound.settings);
|
|
76
76
|
inbound.streamSettings = JSON.parse(inbound.streamSettings);
|
|
77
77
|
inbound.sniffing = JSON.parse(inbound.sniffing);
|
|
78
|
-
inbound.allocate = JSON.parse(inbound.allocate);
|
|
78
|
+
inbound.allocate = inbound.allocate && inbound.allocate.length > 0 ? JSON.parse(inbound.allocate) : {};
|
|
79
79
|
}
|
|
80
80
|
return inbound;
|
|
81
81
|
}
|
|
@@ -196,7 +196,7 @@ class ClientBuilder {
|
|
|
196
196
|
return this;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
build() {
|
|
200
200
|
return {
|
|
201
201
|
id: this.id || crypto.randomUUID(),
|
|
202
202
|
flow: this.flow,
|
|
@@ -210,6 +210,28 @@ class ClientBuilder {
|
|
|
210
210
|
reset: this.reset
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
+
|
|
214
|
+
getLink(host, port, protocol) {
|
|
215
|
+
const id = this.id || crypto.randomUUID();
|
|
216
|
+
const settings = this.parent.streamSettings?.realitySettings;
|
|
217
|
+
if (!settings) throw new Error('Reality settings not found');
|
|
218
|
+
|
|
219
|
+
port = port || this.parent.port;
|
|
220
|
+
protocol = protocol || this.parent.protocol || 'vless';
|
|
221
|
+
|
|
222
|
+
const params = new URLSearchParams({
|
|
223
|
+
security: this.parent.streamSettings?.security || 'reality',
|
|
224
|
+
sni: settings.serverNames[0],
|
|
225
|
+
fp: settings.settings.fingerprint,
|
|
226
|
+
pbk: settings.settings.publicKey,
|
|
227
|
+
sid: settings.shortIds[0],
|
|
228
|
+
spx: settings.settings.spiderX || '/',
|
|
229
|
+
type: this.parent.streamSettings?.network || 'tcp',
|
|
230
|
+
encryption: this.parent.settings?.decryption || 'none'
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
return `${protocol}://${id}@${host}:${port}?${params.toString()}#${encodeURIComponent(this.email || 'default')}`;
|
|
234
|
+
}
|
|
213
235
|
}
|
|
214
236
|
|
|
215
237
|
class RealityBuilder {
|
|
@@ -303,10 +325,29 @@ class RealityBuilder {
|
|
|
303
325
|
if (options.totalGB) builder.setTotalGB(options.totalGB);
|
|
304
326
|
if (options.expiryTime) builder.setExpiryTime(options.expiryTime);
|
|
305
327
|
if (options.tgId) builder.setTgId(options.tgId);
|
|
328
|
+
builder.parent.streamSettings = {
|
|
329
|
+
realitySettings: {
|
|
330
|
+
serverNames: this.serverNames,
|
|
331
|
+
settings: {
|
|
332
|
+
fingerprint: this.fingerprint,
|
|
333
|
+
publicKey: this.publicKey,
|
|
334
|
+
spiderX: '/'
|
|
335
|
+
},
|
|
336
|
+
shortIds: this.shortIds
|
|
337
|
+
}
|
|
338
|
+
};
|
|
306
339
|
this.clients.push(builder);
|
|
307
340
|
return builder;
|
|
308
341
|
}
|
|
309
342
|
|
|
343
|
+
getClientLink(clientIndex = 0, host) {
|
|
344
|
+
if (clientIndex < 0 || clientIndex >= this.clients.length) {
|
|
345
|
+
throw new Error('Invalid client index');
|
|
346
|
+
}
|
|
347
|
+
const client = this.clients[clientIndex];
|
|
348
|
+
return client.getLink(host || this.listenIP || 'localhost', this.port);
|
|
349
|
+
}
|
|
350
|
+
|
|
310
351
|
generateRandomPort() {
|
|
311
352
|
return Math.floor(Math.random() * (65535 - 1024) + 1024);
|
|
312
353
|
}
|