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