feat: Surfboard 支持 Hysteria 2

This commit is contained in:
xream committed 2026-03-30 10:13:18 +08:00
1 parent 01d7673208
commit db7ad0a284
3 files changed
+81 -1

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.21.63",
"version": "2.21.64",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
@@ -30,6 +30,8 @@ export default function Surfboard_Producer() {
return socks5(proxy);
case 'anytls':
return anytls(proxy);
case 'hysteria2':
return hysteria2(proxy);
case 'wireguard-surge':
return wireguard(proxy);
}
@@ -39,6 +41,43 @@ export default function Surfboard_Producer() {
};
return { produce };
}
function hysteria2(proxy) {
if (proxy.obfs || proxy['obfs-password']) {
throw new Error(`Surfboard Hysteria2 does not support obfs`);
}
const result = new Result(proxy);
result.append(`${proxy.name}=hysteria2,${proxy.server},${proxy.port}`);
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
if (isPresent(proxy, 'ports')) {
result.append(`,port-hopping="${proxy.ports.replace(/,/g, ';')}"`);
}
result.appendIfPresent(
`,port-hopping-interval=${proxy['hop-interval']}`,
'hop-interval',
);
// tls verification
result.appendIfPresent(`,sni="${proxy.sni}"`, 'sni');
result.appendIfPresent(
`,skip-cert-verify=${proxy['skip-cert-verify']}`,
'skip-cert-verify',
);
// download-bandwidth
result.appendIfPresent(
`,download-bandwidth=${`${proxy['down']}`.match(/\d+/)?.[0] || 0}`,
'down',
);
// udp
result.appendIfPresent(`,udp-relay=${proxy.udp}`, 'udp');
return result.toString();
}
function anytls(proxy) {
const result = new Result(proxy);
result.append(`${proxy.name}=${proxy.type},${proxy.server},${proxy.port}`);
@@ -2,6 +2,7 @@ import { expect } from 'chai';
import { Base64 } from 'js-base64';
import { describe, it } from 'mocha';
import { ProxyUtils } from '@/core/proxy-utils';
import { produceExternal, UUID } from './helpers';
describe('Proxy text producers', function () {
@@ -131,6 +132,46 @@ describe('Proxy text producers', function () {
);
});
it('produces Surfboard Hysteria2 lines', function () {
const output = produceExternal('Surfboard', {
type: 'hysteria2',
name: 'Surfboard Hysteria2',
server: 'hy2.example.com',
port: 443,
password: 'secret',
ports: '8443,8445-8447',
'hop-interval': 30,
sni: 'peer.example.com',
'skip-cert-verify': true,
down: '100 Mbps',
udp: true,
});
expect(output).to.equal(
'Surfboard Hysteria2=hysteria2,hy2.example.com,443,password="secret",port-hopping="8443;8445-8447",port-hopping-interval=30,sni="peer.example.com",skip-cert-verify=true,download-bandwidth=100,udp-relay=true',
);
});
it('omits Surfboard Hysteria2 lines when obfs is present', function () {
const output = ProxyUtils.produce(
[
{
type: 'hysteria2',
name: 'Surfboard Hysteria2 Obfs',
server: 'hy2.example.com',
port: 443,
password: 'secret',
obfs: 'salamander',
'obfs-password': 'mask',
},
],
'Surfboard',
'external',
);
expect(output).to.equal('');
});
it('produces SurgeMac external lines', function () {
const output = produceExternal('SurgeMac', {
type: 'external',