mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 09:09:00 +08:00
feat: VLESS URI 输入兼容 Shadowrocket 导出格式
This commit is contained in:
parent
f4c4cdba67
commit
8c943176a5
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.162",
|
||||
"version": "2.14.166",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -331,15 +331,27 @@ function URI_VLESS() {
|
||||
};
|
||||
const parse = (line) => {
|
||||
line = line.split('vless://')[1];
|
||||
let isShadowrocket;
|
||||
let parsed = /^(.*?)@(.*?):(\d+)\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
|
||||
if (!parsed) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let [_, base64, other] = /^(.*?)(\?.*?$)/.exec(line);
|
||||
line = `${Base64.decode(base64)}${other}`;
|
||||
parsed = /^(.*?)@(.*?):(\d+)\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
|
||||
isShadowrocket = true;
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
let [__, uuid, server, port, ___, addons = '', name] =
|
||||
/^(.*?)@(.*?):(\d+)\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
|
||||
let [__, uuid, server, port, ___, addons = '', name] = parsed;
|
||||
if (isShadowrocket) {
|
||||
uuid = uuid.replace(/^.*?:/g, '');
|
||||
}
|
||||
|
||||
port = parseInt(`${port}`, 10);
|
||||
uuid = decodeURIComponent(uuid);
|
||||
if (name != null) {
|
||||
name = decodeURIComponent(name);
|
||||
}
|
||||
name = name ?? `VLESS ${server}:${port}`;
|
||||
|
||||
const proxy = {
|
||||
type: 'vless',
|
||||
name,
|
||||
@ -355,9 +367,24 @@ function URI_VLESS() {
|
||||
params[key] = value;
|
||||
}
|
||||
|
||||
proxy.name = name ?? params.remarks ?? `VLESS ${server}:${port}`;
|
||||
|
||||
proxy.tls = params.security && params.security !== 'none';
|
||||
proxy.sni = params.sni;
|
||||
if (isShadowrocket && /TRUE|1/i.test(params.tls)) {
|
||||
proxy.tls = true;
|
||||
params.security = params.security ?? 'reality';
|
||||
}
|
||||
proxy.sni = params.sni ?? params.peer;
|
||||
proxy.flow = params.flow;
|
||||
if (!proxy.flow && isShadowrocket && params.xtls) {
|
||||
// "none" is undefined
|
||||
const flow = [undefined, 'xtls-rprx-direct', 'xtls-rprx-vision'][
|
||||
params.xtls
|
||||
];
|
||||
if (flow) {
|
||||
proxy.flow = flow;
|
||||
}
|
||||
}
|
||||
proxy['client-fingerprint'] = params.fp;
|
||||
proxy.alpn = params.alpn ? params.alpn.split(',') : undefined;
|
||||
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(params.allowInsecure);
|
||||
@ -371,21 +398,28 @@ function URI_VLESS() {
|
||||
opts['short-id'] = params.sid;
|
||||
}
|
||||
if (Object.keys(opts).length > 0) {
|
||||
// proxy[`${params.security}-opts`] = opts;
|
||||
proxy[`${params.security}-opts`] = opts;
|
||||
}
|
||||
}
|
||||
|
||||
proxy.network = params.type;
|
||||
if (!proxy.network && isShadowrocket && params.obfs) {
|
||||
proxy.network = params.obfs;
|
||||
}
|
||||
if (proxy.network && !['tcp', 'none'].includes(proxy.network)) {
|
||||
const opts = {};
|
||||
if (params.path) {
|
||||
opts.path = params.path;
|
||||
}
|
||||
if (params.host) {
|
||||
opts.headers = { Host: params.host };
|
||||
}
|
||||
if (params.serviceName) {
|
||||
opts[`${proxy.network}-service-name`] = params.serviceName;
|
||||
} else if (isShadowrocket && params.path) {
|
||||
opts[`${proxy.network}-service-name`] = params.path;
|
||||
delete params.path;
|
||||
}
|
||||
if (params.path) {
|
||||
opts.path = params.path;
|
||||
}
|
||||
// https://github.com/XTLS/Xray-core/issues/91
|
||||
if (['grpc'].includes(proxy.network)) {
|
||||
|
@ -31,7 +31,7 @@ export async function getFlowHeaders(url, ua, timeout) {
|
||||
const cached = headersResourceCache.get(url);
|
||||
let flowInfo;
|
||||
if (!$arguments?.noCache && cached) {
|
||||
$.info(`使用缓存的流量信息: ${url}`);
|
||||
// $.info(`使用缓存的流量信息: ${url}`);
|
||||
flowInfo = cached;
|
||||
} else {
|
||||
const { defaultFlowUserAgent, defaultTimeout } = $.read(SETTINGS_KEY);
|
||||
@ -42,7 +42,7 @@ export async function getFlowHeaders(url, ua, timeout) {
|
||||
const requestTimeout = timeout || defaultTimeout;
|
||||
const http = HTTP();
|
||||
try {
|
||||
$.info(`使用 HEAD 方法获取流量信息: ${url}`);
|
||||
// $.info(`使用 HEAD 方法获取流量信息: ${url}`);
|
||||
const { headers } = await http.head({
|
||||
url: url
|
||||
.split(/[\r\n]+/)
|
||||
|
Loading…
x
Reference in New Issue
Block a user