This commit is contained in:
Christine. 2024-12-03 16:03:21 +08:00 committed by GitHub
parent ae5b2cfb79
commit f400f900e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -36,7 +36,7 @@ export default function parseUri(uri: string): IProxyConfig {
function getIfNotBlank( function getIfNotBlank(
value: string | undefined, value: string | undefined,
dft?: string dft?: string,
): string | undefined { ): string | undefined {
return value && value.trim() !== "" ? value : dft; return value && value.trim() !== "" ? value : dft;
} }
@ -180,7 +180,7 @@ function URI_SS(line: string): IProxyShadowsocksConfig {
if (v2rayPlugin) { if (v2rayPlugin) {
proxy.plugin = "v2ray-plugin"; proxy.plugin = "v2ray-plugin";
proxy["plugin-opts"] = JSON.parse( proxy["plugin-opts"] = JSON.parse(
decodeBase64OrOriginal(v2rayPlugin) decodeBase64OrOriginal(v2rayPlugin),
); );
} }
} }
@ -193,7 +193,7 @@ function URI_SS(line: string): IProxyShadowsocksConfig {
const portIdx = serverAndPort?.lastIndexOf(":") ?? 0; const portIdx = serverAndPort?.lastIndexOf(":") ?? 0;
proxy.server = serverAndPort?.substring(0, portIdx) ?? ""; proxy.server = serverAndPort?.substring(0, portIdx) ?? "";
proxy.port = parseInt( proxy.port = parseInt(
`${serverAndPort?.substring(portIdx + 1)}`.match(/\d+/)?.[0] ?? "" `${serverAndPort?.substring(portIdx + 1)}`.match(/\d+/)?.[0] ?? "",
); );
const userInfo = userInfoStr.match(/(^.*?):(.*$)/); const userInfo = userInfoStr.match(/(^.*?):(.*$)/);
proxy.cipher = getCipher(userInfo?.[1]); proxy.cipher = getCipher(userInfo?.[1]);
@ -252,7 +252,7 @@ function URI_SSR(line: string): IProxyshadowsocksRConfig {
const serverAndPort = line.substring(0, splitIdx); const serverAndPort = line.substring(0, splitIdx);
const server = serverAndPort.substring(0, serverAndPort.lastIndexOf(":")); const server = serverAndPort.substring(0, serverAndPort.lastIndexOf(":"));
const port = parseInt( const port = parseInt(
serverAndPort.substring(serverAndPort.lastIndexOf(":") + 1) serverAndPort.substring(serverAndPort.lastIndexOf(":") + 1),
); );
let params = line let params = line
@ -284,12 +284,12 @@ function URI_SSR(line: string): IProxyshadowsocksRConfig {
...proxy, ...proxy,
name: other_params.remarks name: other_params.remarks
? decodeBase64OrOriginal(other_params.remarks).trim() ? decodeBase64OrOriginal(other_params.remarks).trim()
: proxy.server ?? "", : (proxy.server ?? ""),
"protocol-param": getIfNotBlank( "protocol-param": getIfNotBlank(
decodeBase64OrOriginal(other_params.protoparam || "").replace(/\s/g, "") decodeBase64OrOriginal(other_params.protoparam || "").replace(/\s/g, ""),
), ),
"obfs-param": getIfNotBlank( "obfs-param": getIfNotBlank(
decodeBase64OrOriginal(other_params.obfsparam || "").replace(/\s/g, "") decodeBase64OrOriginal(other_params.obfsparam || "").replace(/\s/g, ""),
), ),
}; };
return proxy; return proxy;
@ -330,7 +330,7 @@ function URI_VMESS(line: string): IProxyVmessConfig {
proxy["ws-opts"] = { proxy["ws-opts"] = {
path: path:
(getIfNotBlank(params["obfs-path"]) || '"/"').match( (getIfNotBlank(params["obfs-path"]) || '"/"').match(
/^"(.*)"$/ /^"(.*)"$/,
)?.[1] || "/", )?.[1] || "/",
headers: { headers: {
Host: Host:
@ -492,6 +492,9 @@ function URI_VMESS(line: string): IProxyVmessConfig {
} }
} }
/**
* VLess URL Decode.
*/
function URI_VLESS(line: string): IProxyVlessConfig { function URI_VLESS(line: string): IProxyVlessConfig {
line = line.split("vless://")[1]; line = line.split("vless://")[1];
let isShadowrocket; let isShadowrocket;
@ -571,9 +574,11 @@ function URI_VLESS(line: string): IProxyVlessConfig {
if (params.headerType === "http") { if (params.headerType === "http") {
proxy.network = "http"; proxy.network = "http";
} else { } else if (params.type === "ws") {
proxy.network = "ws"; proxy.network = "ws";
httpupgrade = true; httpupgrade = true;
} else {
proxy.network = "tcp";
} }
if (!proxy.network && isShadowrocket && params.obfs) { if (!proxy.network && isShadowrocket && params.obfs) {
switch (params.type) { switch (params.type) {
@ -619,7 +624,7 @@ function URI_VLESS(line: string): IProxyVlessConfig {
opts["v2ray-http-upgrade-fast-open"] = true; opts["v2ray-http-upgrade-fast-open"] = true;
} }
if (Object.keys(opts).length > 0) { if (Object.keys(opts).length > 0) {
proxy[`${proxy.network}-opts`] = opts; proxy[`ws-opts`] = opts;
} }
} }
@ -631,7 +636,6 @@ function URI_VLESS(line: string): IProxyVlessConfig {
proxy.servername = Array.isArray(httpHost) ? httpHost[0] : httpHost; proxy.servername = Array.isArray(httpHost) ? httpHost[0] : httpHost;
} }
} }
return proxy; return proxy;
} }