@@ -331,15 +331,27 @@ function URI_VLESS() {
331
331
} ;
332
332
const parse = ( line ) => {
333
333
line = line . split ( 'vless://' ) [ 1 ] ;
334
+ let isShadowrocket ;
335
+ let parsed = / ^ ( .* ?) @ ( .* ?) : ( \d + ) \/ ? ( \? ( .* ?) ) ? (?: # ( .* ?) ) ? $ / . exec ( line ) ;
336
+ if ( ! parsed ) {
337
+ // eslint-disable-next-line no-unused-vars
338
+ let [ _ , base64 , other ] = / ^ ( .* ?) ( \? .* ?$ ) / . exec ( line ) ;
339
+ line = `${ Base64 . decode ( base64 ) } ${ other } ` ;
340
+ parsed = / ^ ( .* ?) @ ( .* ?) : ( \d + ) \/ ? ( \? ( .* ?) ) ? (?: # ( .* ?) ) ? $ / . exec ( line ) ;
341
+ isShadowrocket = true ;
342
+ }
334
343
// eslint-disable-next-line no-unused-vars
335
- let [ __ , uuid , server , port , ___ , addons = '' , name ] =
336
- / ^ ( .* ?) @ ( .* ?) : ( \d + ) \/ ? ( \? ( .* ?) ) ? (?: # ( .* ?) ) ? $ / . exec ( line ) ;
344
+ let [ __ , uuid , server , port , ___ , addons = '' , name ] = parsed ;
345
+ if ( isShadowrocket ) {
346
+ uuid = uuid . replace ( / ^ .* ?: / g, '' ) ;
347
+ }
348
+
337
349
port = parseInt ( `${ port } ` , 10 ) ;
338
350
uuid = decodeURIComponent ( uuid ) ;
339
351
if ( name != null ) {
340
352
name = decodeURIComponent ( name ) ;
341
353
}
342
- name = name ?? `VLESS ${ server } : ${ port } ` ;
354
+
343
355
const proxy = {
344
356
type : 'vless' ,
345
357
name,
@@ -355,9 +367,29 @@ function URI_VLESS() {
355
367
params [ key ] = value ;
356
368
}
357
369
370
+ proxy . name = name ?? params . remarks ?? `VLESS ${ server } :${ port } ` ;
371
+
358
372
proxy . tls = params . security && params . security !== 'none' ;
359
- proxy . sni = params . sni ;
373
+ if (
374
+ isShadowrocket &&
375
+ ! proxy . tls &&
376
+ params . tls &&
377
+ ! / 0 | n o n e | f a l s e / . test ( params . tls )
378
+ ) {
379
+ proxy . tls = true ;
380
+ params . security = params . security ?? 'reality' ;
381
+ }
382
+ proxy . sni = params . sni ?? params . peer ;
360
383
proxy . flow = params . flow ;
384
+ if ( ! proxy . flow && isShadowrocket && params . xtls ) {
385
+ // "none" is undefined
386
+ const flow = [ undefined , 'xtls-rprx-direct' , 'xtls-rprx-vision' ] [
387
+ params . xtls
388
+ ] ;
389
+ if ( flow ) {
390
+ proxy . flow = flow ;
391
+ }
392
+ }
361
393
proxy [ 'client-fingerprint' ] = params . fp ;
362
394
proxy . alpn = params . alpn ? params . alpn . split ( ',' ) : undefined ;
363
395
proxy [ 'skip-cert-verify' ] = / ( T R U E ) | 1 / i. test ( params . allowInsecure ) ;
@@ -371,21 +403,28 @@ function URI_VLESS() {
371
403
opts [ 'short-id' ] = params . sid ;
372
404
}
373
405
if ( Object . keys ( opts ) . length > 0 ) {
406
+ // proxy[`${params.security}-opts`] = opts;
374
407
proxy [ `${ params . security } -opts` ] = opts ;
375
408
}
376
409
}
377
410
378
411
proxy . network = params . type ;
412
+ if ( ! proxy . network && isShadowrocket && params . obfs ) {
413
+ proxy . network = params . obfs ;
414
+ }
379
415
if ( proxy . network && ! [ 'tcp' , 'none' ] . includes ( proxy . network ) ) {
380
416
const opts = { } ;
381
- if ( params . path ) {
382
- opts . path = params . path ;
383
- }
384
417
if ( params . host ) {
385
418
opts . headers = { Host : params . host } ;
386
419
}
387
420
if ( params . serviceName ) {
388
421
opts [ `${ proxy . network } -service-name` ] = params . serviceName ;
422
+ } else if ( isShadowrocket && params . path ) {
423
+ opts [ `${ proxy . network } -service-name` ] = params . path ;
424
+ delete params . path ;
425
+ }
426
+ if ( params . path ) {
427
+ opts . path = params . path ;
389
428
}
390
429
// https://github.com/XTLS/Xray-core/issues/91
391
430
if ( [ 'grpc' ] . includes ( proxy . network ) ) {
0 commit comments