Skip to content

Commit

Permalink
feat: support Surge tuic-v5 format
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Jun 15, 2023
1 parent a9fb731 commit bedff82
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"@types/chai": "^4.3.5",
"@types/debug": "^4.1.8",
"@types/fs-extra": "^11.0.1",
"@types/ini": "^1.3.31",
"@types/inquirer": "^8.2.6",
"@types/ioredis-mock": "^8.2.2",
"@types/lodash": "^4.14.195",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/__tests__/__snapshots__/index.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ Generated by [AVA](https://avajs.dev).
SURFBOARD: 'Surfboard',
SURGE: 'Surge',
},
defineProvider: Function defineProvider {},
defineBlackSSLProvider: Function defineBlackSSLProvider {},
defineClashProvider: Function defineClashProvider {},
defineCustomProvider: Function defineCustomProvider {},
defineShadowsocksJsonSubscribeProvider: Function defineShadowsocksJsonSubscribeProvider {},
defineShadowsocksSubscribeProvider: Function defineShadowsocksSubscribeProvider {},
defineShadowsocksrSubscribeProvider: Function defineShadowsocksrSubscribeProvider {},
defineSsdProvider: Function defineSsdProvider {},
defineSurgioConfig: Function defineSurgioConfig {},
defineTrojanProvider: Function defineTrojanProvider {},
defineV2rayNSubscribeProvider: Function defineV2rayNSubscribeProvider {},
utils: {
SortFilterWithSortedFilters: Function SortFilterWithSortedFilters {},
SortFilterWithSortedKeywords: Function SortFilterWithSortedKeywords {},
Expand Down
Binary file modified src/__tests__/__snapshots__/index.test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion src/generator/__tests__/artifact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { loadConfig } from '../../config'
import { Artifact } from '../artifact'
import { getEngine } from '../template'

const resolve = (p) => join(__dirname, '../../../test/fixture/', p)
const resolve = (p: string) => join(__dirname, '../../../test/fixture/', p)

test('new Artifact()', async (t) => {
const fixture = resolve('plain')
Expand Down
2 changes: 1 addition & 1 deletion src/provider/__tests__/ClashProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ test.serial(

test('ClashProvider with hooks', async (t) => {
const afterNodeListResponse = sinon.spy((nodeList) => {
nodeList.forEach((node) => {
nodeList.forEach((node: any) => {
node.nodeName = 'override'
})
})
Expand Down
Binary file modified src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion src/utils/__tests__/surge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ test('getSurgeNodes - Tuic', (t) => {
'测试 Tuic = tuic, example.com, 443, token=token, server-cert-fingerprint-sha256=sha256',
'测试 Tuic = tuic, example.com, 443, token=token, alpn=h3',
'测试 Tuic = tuic, example.com, 443, token=token, sni=sni.example.com, skip-cert-verify=true, alpn=h3',
'测试 Tuic = tuic, example.com, 443, password=password, uuid=uuid, sni=sni.example.com, skip-cert-verify=true, version=5, alpn=h3',
'测试 Tuic = tuic-v5, example.com, 443, password=password, uuid=uuid, sni=sni.example.com, skip-cert-verify=true, alpn=h3',
].join('\n'),
)
})
Expand Down
34 changes: 31 additions & 3 deletions src/utils/surge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,37 @@ function nodeListMapper(
}

case NodeTypeEnum.Tuic: {
if ('version' in nodeConfig && Number(nodeConfig.version) === 5) {
const result = [
'tuic-v5',
nodeConfig.hostname,
nodeConfig.port,
...pickAndFormatStringList(
nodeConfig,
[
'password',
'uuid',
'sni',
'underlyingProxy',
'testUrl',
'skipCertVerify',
'serverCertFingerprintSha256',
],
{
keyFormat: 'kebabCase',
},
),
...(Array.isArray(nodeConfig.alpn)
? [`alpn=${nodeConfig.alpn.join(',')}`]
: []),
]

return [
nodeConfig.nodeName,
[nodeConfig.nodeName, result.join(', ')].join(' = '),
]
}

const result = [
'tuic',
nodeConfig.hostname,
Expand All @@ -483,14 +514,11 @@ function nodeListMapper(
nodeConfig,
[
'token',
'password',
'uuid',
'sni',
'underlyingProxy',
'testUrl',
'skipCertVerify',
'serverCertFingerprintSha256',
'version',
],
{
keyFormat: 'kebabCase',
Expand Down
2 changes: 1 addition & 1 deletion test/cli.cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ini from 'ini'
import { test, expect } from '@oclif/test'

const fixture = join(__dirname, './fixture')
const resolve = (p) => join(fixture, p)
const resolve = (p: string) => join(fixture, p)

afterEach(async () => {
process.env.ENV_SURGIO_PROJECT_DIR = undefined
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"rootDir": "./src",
// https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
"target": "ES2022",
"module": "Node16",
Expand Down

0 comments on commit bedff82

Please sign in to comment.