feat: 支持 Hysteria(v1) URI

This commit is contained in:
xream
2024-02-03 17:54:37 +08:00
parent 5d3fc499ce
commit 02d54208b0
3 changed files with 131 additions and 2 deletions

View File

@@ -6,6 +6,11 @@ export default function URI_Producer() {
const type = 'SINGLE';
const produce = (proxy) => {
let result = '';
delete proxy.subName;
delete proxy.collectionName;
if (['trojan', 'tuic', 'hysteria', 'hysteria2'].includes(proxy.type)) {
delete proxy.tls;
}
if (proxy.server && isIPv6(proxy.server)) {
proxy.server = `[${proxy.server}]`;
}
@@ -285,6 +290,61 @@ export default function URI_Producer() {
'&',
)}#${encodeURIComponent(proxy.name)}`;
break;
case 'hysteria':
let hysteriaParams = [];
Object.keys(proxy).forEach((key) => {
if (!['name', 'type', 'server', 'port'].includes(key)) {
const i = key.replace(/-/, '_');
if (['alpn'].includes(key)) {
if (proxy[key]) {
hysteriaParams.push(
`${i}=${encodeURIComponent(
Array.isArray(proxy[key])
? proxy[key][0]
: proxy[key],
)}`,
);
}
} else if (['skip-cert-verify'].includes(key)) {
if (proxy[key]) {
hysteriaParams.push(`insecure=1`);
}
} else if (['tfo', 'fast-open'].includes(key)) {
if (
proxy[key] &&
!hysteriaParams.includes('fastopen=1')
) {
hysteriaParams.push(`fastopen=1`);
}
} else if (['ports'].includes(key)) {
hysteriaParams.push(`mport=${proxy[key]}`);
} else if (['auth-str'].includes(key)) {
hysteriaParams.push(`auth=${proxy[key]}`);
} else if (['up'].includes(key)) {
hysteriaParams.push(`upmbps=${proxy[key]}`);
} else if (['down'].includes(key)) {
hysteriaParams.push(`downmbps=${proxy[key]}`);
} else if (['_obfs'].includes(key)) {
hysteriaParams.push(`obfs=${proxy[key]}`);
} else if (['obfs'].includes(key)) {
hysteriaParams.push(`obfsParam=${proxy[key]}`);
} else if (['sni'].includes(key)) {
hysteriaParams.push(`peer=${proxy[key]}`);
} else if (proxy[key]) {
hysteriaParams.push(
`${i}=${encodeURIComponent(proxy[key])}`,
);
}
}
});
result = `hysteria://${proxy.server}:${
proxy.port
}?${hysteriaParams.join('&')}#${encodeURIComponent(
proxy.name,
)}`;
break;
case 'tuic':
if (!proxy.token || proxy.token.length === 0) {
let tuicParams = [];