mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-14 05:25:58 +08:00
feat: Added support for VMess URI in other formats and VMess without transport settings
This commit is contained in:
parent
9b0c15ebc2
commit
afb9296158
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.24",
|
"version": "2.14.25",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -157,7 +157,7 @@ function URI_VMess() {
|
|||||||
};
|
};
|
||||||
const parse = (line) => {
|
const parse = (line) => {
|
||||||
line = line.split('vmess://')[1];
|
line = line.split('vmess://')[1];
|
||||||
const content = Base64.decode(line);
|
let content = Base64.decode(line);
|
||||||
if (/=\s*vmess/.test(content)) {
|
if (/=\s*vmess/.test(content)) {
|
||||||
// Quantumult VMess URI format
|
// Quantumult VMess URI format
|
||||||
const partitions = content.split(',').map((p) => p.trim());
|
const partitions = content.split(',').map((p) => p.trim());
|
||||||
@ -209,17 +209,49 @@ function URI_VMess() {
|
|||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
} else {
|
} else {
|
||||||
// V2rayN URI format
|
let params = {};
|
||||||
const params = JSON.parse(content);
|
|
||||||
|
try {
|
||||||
|
// V2rayN URI format
|
||||||
|
params = JSON.parse(content);
|
||||||
|
} catch (e) {
|
||||||
|
// console.error(e);
|
||||||
|
// Shadowrocket URI format
|
||||||
|
let [_, base64Line, qs] = /(^[^?]+?)\/?\?(.*)$/.exec(line);
|
||||||
|
content = Base64.decode(base64Line);
|
||||||
|
|
||||||
|
for (const addon of qs.split('&')) {
|
||||||
|
const [key, valueRaw] = addon.split('=');
|
||||||
|
let value = valueRaw;
|
||||||
|
value = decodeURIComponent(valueRaw);
|
||||||
|
if (value.indexOf(',') === -1) {
|
||||||
|
params[key] = value;
|
||||||
|
} else {
|
||||||
|
params[key] = value.split(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`content`, content);
|
||||||
|
console.log(`params`, params);
|
||||||
|
let [__, cipher, uuid, server, port] =
|
||||||
|
/(^[^:]+?):([^:]+?)@(.*):(\d+)$/.exec(content);
|
||||||
|
|
||||||
|
params.scy = cipher;
|
||||||
|
params.id = uuid;
|
||||||
|
params.port = port;
|
||||||
|
params.add = server;
|
||||||
|
}
|
||||||
const proxy = {
|
const proxy = {
|
||||||
name: params.ps,
|
name: params.ps ?? params.remark,
|
||||||
type: 'vmess',
|
type: 'vmess',
|
||||||
server: params.add,
|
server: params.add,
|
||||||
port: params.port,
|
port: parseInt(getIfPresent(params.port), 10),
|
||||||
cipher: getIfPresent(params.scy, 'auto'),
|
cipher: getIfPresent(params.scy, 'auto'),
|
||||||
uuid: params.id,
|
uuid: params.id,
|
||||||
alterId: parseInt(getIfPresent(params.aid, 0)),
|
alterId: parseInt(
|
||||||
tls: params.tls === 'tls' || params.tls === true,
|
getIfPresent(params.aid ?? params.alterId, 0),
|
||||||
|
10,
|
||||||
|
),
|
||||||
|
tls: ['tls', true, 1, '1'].includes(params.tls),
|
||||||
'skip-cert-verify': isPresent(params.verify_cert)
|
'skip-cert-verify': isPresent(params.verify_cert)
|
||||||
? !params.verify_cert
|
? !params.verify_cert
|
||||||
: undefined,
|
: undefined,
|
||||||
@ -229,16 +261,40 @@ function URI_VMess() {
|
|||||||
proxy.sni = params.sni;
|
proxy.sni = params.sni;
|
||||||
}
|
}
|
||||||
// handle obfs
|
// handle obfs
|
||||||
if (params.net === 'ws') {
|
if (params.net === 'ws' || params.obfs === 'websocket') {
|
||||||
proxy.network = 'ws';
|
proxy.network = 'ws';
|
||||||
proxy['ws-opts'] = {
|
} else if (params.net === 'tcp' || params.obfs === 'http') {
|
||||||
path: getIfNotBlank(params.path),
|
proxy.network = 'http';
|
||||||
headers: { Host: getIfNotBlank(params.host) },
|
}
|
||||||
};
|
if (proxy.network) {
|
||||||
|
let transportHost = params.host ?? params.obfsParam;
|
||||||
|
let transportPath = params.path;
|
||||||
|
|
||||||
|
if (proxy.network === 'http') {
|
||||||
|
if (transportHost) {
|
||||||
|
transportHost = Array.isArray(transportHost)
|
||||||
|
? transportHost[0]
|
||||||
|
: transportHost;
|
||||||
|
}
|
||||||
|
if (transportPath) {
|
||||||
|
transportPath = Array.isArray(transportPath)
|
||||||
|
? transportPath[0]
|
||||||
|
: transportPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (transportPath || transportHost) {
|
||||||
|
proxy[`${proxy.network}-opts`] = {
|
||||||
|
path: getIfNotBlank(transportPath),
|
||||||
|
headers: { Host: getIfNotBlank(transportHost) },
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
delete proxy.network;
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/docs/config.yaml#L413
|
// https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/docs/config.yaml#L413
|
||||||
// sni 优先级应高于 host
|
// sni 优先级应高于 host
|
||||||
if (proxy.tls && !proxy.sni && params.host) {
|
if (proxy.tls && !proxy.sni && transportHost) {
|
||||||
proxy.sni = params.host;
|
proxy.sni = transportHost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
|
@ -87,6 +87,7 @@ params = "/"? "?" head:param tail:("&"@param)* {
|
|||||||
proxy.network = "ws";
|
proxy.network = "ws";
|
||||||
$set(proxy, "ws-opts.path", params["wspath"]);
|
$set(proxy, "ws-opts.path", params["wspath"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params["type"]) {
|
if (params["type"]) {
|
||||||
proxy.network = params["type"]
|
proxy.network = params["type"]
|
||||||
if (params["path"]) {
|
if (params["path"]) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user