Skip to content

Commit cb98bcd

Browse files
authored
Merge pull request #320 from AzunyanDaisuki/master
2 parents 2467c49 + 39bdfb1 commit cb98bcd

File tree

4 files changed

+189
-2
lines changed

4 files changed

+189
-2
lines changed

src/provider/ClashProvider.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,19 @@ export const parseClashConfig = (
377377
if (typeof item['client-fingerprint'] === 'string') {
378378
vmessNode.clientFingerprint = item['client-fingerprint']
379379
}
380+
if (Array.isArray(item.alpn) && item.alpn.length > 0) {
381+
vmessNode.alpn = item.alpn
382+
}
380383

381384
vmessNode.skipCertVerify = item['skip-cert-verify'] === true
382385
vmessNode.tls13 = tls13 === true
383386
}
384387

385388
if (vmessNode.type === NodeTypeEnum.Vless) {
386-
vmessNode.flow = item.flow
389+
if (typeof item.flow === 'string') {
390+
vmessNode.flow = item.flow
391+
}
392+
387393
if (typeof item.encryption === 'string') {
388394
vmessNode.encryption = item.encryption
389395
}

src/provider/__tests__/ClashProvider.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,71 @@ foo: bar
357357
})
358358

359359
test('vmess Configurations', (t) => {
360+
t.deepEqual(
361+
parseClashConfig([
362+
{
363+
type: 'vmess',
364+
name: 'vmess meta alpn',
365+
server: 'server',
366+
port: 443,
367+
uuid: 'uuid',
368+
alterId: 32,
369+
cipher: 'auto',
370+
network: 'tcp',
371+
tls: true,
372+
alpn: ['h2', 'http/1.1'],
373+
},
374+
]),
375+
[
376+
{
377+
type: NodeTypeEnum.Vmess,
378+
nodeName: 'vmess meta alpn',
379+
hostname: 'server',
380+
port: 443,
381+
uuid: 'uuid',
382+
alterId: '32',
383+
method: 'auto',
384+
network: 'tcp',
385+
tls: true,
386+
alpn: ['h2', 'http/1.1'],
387+
udpRelay: false,
388+
skipCertVerify: false,
389+
tls13: false,
390+
},
391+
],
392+
)
393+
394+
t.deepEqual(
395+
parseClashConfig([
396+
{
397+
type: 'vless',
398+
name: 'vless alpn',
399+
server: 'server',
400+
port: 443,
401+
uuid: 'uuid',
402+
cipher: 'none',
403+
network: 'tcp',
404+
tls: true,
405+
alpn: ['h2'],
406+
},
407+
]),
408+
[
409+
{
410+
type: NodeTypeEnum.Vless,
411+
nodeName: 'vless alpn',
412+
hostname: 'server',
413+
port: 443,
414+
uuid: 'uuid',
415+
method: 'none',
416+
network: 'tcp',
417+
alpn: ['h2'],
418+
udpRelay: false,
419+
skipCertVerify: false,
420+
tls13: false,
421+
},
422+
],
423+
)
424+
360425
t.deepEqual(
361426
parseClashConfig([
362427
{

src/utils/__tests__/clash.test.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,116 @@ test('getClashNodes', async (t) => {
395395
},
396396
],
397397
)
398+
t.deepEqual(
399+
clash.getClashNodes([
400+
{
401+
alterId: '64',
402+
hostname: '1.1.1.1',
403+
method: 'auto',
404+
network: 'tcp',
405+
nodeName: 'Test Meta VMess ALPN',
406+
port: 8080,
407+
tls: true,
408+
alpn: ['h2', 'http/1.1'],
409+
type: NodeTypeEnum.Vmess,
410+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
411+
clashConfig: {
412+
clashCore: 'clash.meta',
413+
},
414+
},
415+
{
416+
type: NodeTypeEnum.Vless,
417+
nodeName: 'Test Meta VLESS ALPN',
418+
hostname: 'server',
419+
port: 443,
420+
uuid: 'uuid',
421+
method: 'none',
422+
network: 'tcp',
423+
alpn: ['h2'],
424+
encryption: 'none',
425+
clashConfig: {
426+
enableVless: true,
427+
clashCore: 'clash.meta',
428+
},
429+
},
430+
{
431+
alterId: '64',
432+
hostname: '1.1.1.1',
433+
method: 'auto',
434+
network: 'tcp',
435+
nodeName: 'Test Non Meta VMess ALPN',
436+
port: 8080,
437+
alpn: ['h2'],
438+
type: NodeTypeEnum.Vmess,
439+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
440+
},
441+
{
442+
alterId: '64',
443+
hostname: '1.1.1.1',
444+
method: 'auto',
445+
network: 'tcp',
446+
nodeName: 'Test Meta VMess No ALPN',
447+
port: 8080,
448+
tls: true,
449+
type: NodeTypeEnum.Vmess,
450+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
451+
clashConfig: {
452+
clashCore: 'clash.meta',
453+
},
454+
},
455+
]),
456+
[
457+
{
458+
alterId: '64',
459+
cipher: 'auto',
460+
name: 'Test Meta VMess ALPN',
461+
network: 'tcp',
462+
server: '1.1.1.1',
463+
port: 8080,
464+
tls: true,
465+
alpn: ['h2', 'http/1.1'],
466+
type: 'vmess',
467+
udp: false,
468+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
469+
},
470+
{
471+
type: 'vless',
472+
name: 'Test Meta VLESS ALPN',
473+
server: 'server',
474+
port: 443,
475+
uuid: 'uuid',
476+
cipher: 'none',
477+
udp: false,
478+
network: 'tcp',
479+
alpn: ['h2'],
480+
encryption: 'none',
481+
tls: true,
482+
},
483+
{
484+
alterId: '64',
485+
cipher: 'auto',
486+
name: 'Test Non Meta VMess ALPN',
487+
network: 'tcp',
488+
server: '1.1.1.1',
489+
port: 8080,
490+
type: 'vmess',
491+
udp: false,
492+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
493+
},
494+
{
495+
alterId: '64',
496+
cipher: 'auto',
497+
name: 'Test Meta VMess No ALPN',
498+
network: 'tcp',
499+
server: '1.1.1.1',
500+
port: 8080,
501+
tls: true,
502+
type: 'vmess',
503+
udp: false,
504+
uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd',
505+
},
506+
],
507+
)
398508

399509
t.deepEqual(
400510
clash.getClashNodes([

src/utils/clash.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ function nodeListMapper(nodeConfig: PossibleNodeConfigType) {
202202
}
203203

204204
if (nodeConfig.type === NodeTypeEnum.Vless) {
205-
vmessNode.flow = nodeConfig.flow
205+
if (typeof nodeConfig.flow === 'string') {
206+
vmessNode.flow = nodeConfig.flow
207+
}
208+
206209
if (typeof nodeConfig.encryption === 'string') {
207210
vmessNode.encryption = nodeConfig.encryption
208211
}
@@ -242,6 +245,9 @@ function nodeListMapper(nodeConfig: PossibleNodeConfigType) {
242245
if (clashConfig.clashCore === 'clash.meta' && nodeConfig.sni) {
243246
vmessNode.servername = nodeConfig.sni
244247
}
248+
if (clashConfig.clashCore === 'clash.meta' && nodeConfig.alpn) {
249+
vmessNode.alpn = nodeConfig.alpn
250+
}
245251
if (nodeConfig.clientFingerprint) {
246252
vmessNode['client-fingerprint'] = nodeConfig.clientFingerprint
247253
}

0 commit comments

Comments
 (0)