Compare commits

...

12 Commits

16 changed files with 204 additions and 24 deletions

View File

@@ -39,7 +39,7 @@ Core functionalities:
- [x] Loon (SS, SSR, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard, VLESS, Hysteria 2)
- [x] Surge (Direct, SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, TUIC, Snell, Hysteria 2, SSH(Password authentication only), External Proxy Program(only for macOS), WireGuard(Surge to Surge))
- [x] Surfboard (SS, VMess, Trojan, HTTP, SOCKS5, SOCKS5-TLS, WireGuard(Surfboard to Surfboard))
- [x] Clash.Meta (Direct, SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC)
- [x] Clash.Meta (Direct, SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC, SSH, mieru)
- [x] Stash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, TUIC, Juicity, SSH)
- [x] Clash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard)

View File

@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.445",
"version": "2.15.2",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@@ -929,6 +929,8 @@ function Clash_All() {
const proxy = JSON.parse(line);
if (
![
'mieru',
'juicity',
'ss',
'ssr',
'vmess',

View File

@@ -8,6 +8,8 @@ export default function ClashMeta_Producer() {
if (opts['include-unsupported-proxy']) return true;
if (proxy.type === 'snell' && String(proxy.version) === '4') {
return false;
} else if (['juicity'].includes(proxy.type)) {
return false;
}
return true;
})

View File

@@ -8,6 +8,8 @@ export default function ShadowRocket_Producer() {
if (opts['include-unsupported-proxy']) return true;
if (proxy.type === 'snell' && String(proxy.version) === '4') {
return false;
} else if (['mieru'].includes(proxy.type)) {
return false;
}
return true;
})

View File

@@ -3,7 +3,7 @@ import $ from '@/core/app';
import { isIPv4, isIPv6 } from '@/utils';
const detourParser = (proxy, parsedProxy) => {
if (proxy['dialer-proxy']) parsedProxy.detour = proxy['dialer-proxy'];
parsedProxy.detour = proxy['dialer-proxy'] || proxy.detour;
};
const tfoParser = (proxy, parsedProxy) => {
parsedProxy.tcp_fast_open = false;
@@ -214,7 +214,11 @@ const tlsParser = (proxy, parsedProxy) => {
proxy['reality-opts']['short-id'];
parsedProxy.tls.utls = { enabled: true };
}
if (proxy['client-fingerprint'] && proxy['client-fingerprint'] !== '')
if (
!['hysteria', 'hysteria2', 'tuic'].includes(proxy.type) &&
proxy['client-fingerprint'] &&
proxy['client-fingerprint'] !== ''
)
parsedProxy.tls.utls = {
enabled: true,
fingerprint: proxy['client-fingerprint'],

View File

@@ -47,7 +47,16 @@ let resourceUrl = typeof $resourceUrl !== 'undefined' ? $resourceUrl : '';
if ((!result || /^\s*$/.test(result)) && resourceUrl) {
console.log(`解析器: 尝试从 ${resourceUrl} 获取订阅`);
try {
let raw = await download(resourceUrl, arg?.ua, arg?.timeout);
let raw = await download(
resourceUrl,
arg?.ua,
arg?.timeout,
undefined,
undefined,
undefined,
undefined,
true,
);
let proxies = ProxyUtils.parse(raw);
result = ProxyUtils.produce(proxies, 'Loon', undefined, {
'include-unsupported-proxy': arg?.includeUnsupportedProxy,

View File

@@ -63,7 +63,7 @@ async function downloadSubscription(req, res) {
$.info(
`正在下载订阅:${name}\n请求 User-Agent: ${
req.headers['user-agent'] || req.headers['User-Agent']
}`,
}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
);
let {
url,
@@ -213,9 +213,29 @@ async function downloadSubscription(req, res) {
}
}
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
[subUserInfo, flowInfo].filter((i) => i).join('; '),
);
}
@@ -255,7 +275,7 @@ async function downloadSubscription(req, res) {
);
}
} else {
$.error(`🌍 Sub-Store 下载订阅失败`, `❌ 未找到订阅:${name}`);
$.error(`🌍 Sub-Store 下载订阅失败\n❌ 未找到订阅:${name}`);
failed(
res,
new ResourceNotFoundError(
@@ -283,7 +303,7 @@ async function downloadCollection(req, res) {
$.info(
`正在下载组合订阅:${name}\n请求 User-Agent: ${
req.headers['user-agent'] || req.headers['User-Agent']
}`,
}\n请求 target: ${req.query.target}\n实际输出: ${platform}`,
);
let {
@@ -355,13 +375,12 @@ async function downloadCollection(req, res) {
proxy,
noCache,
});
let subUserInfoOfSub;
// forward flow header from the first subscription in this collection
const allSubs = $.read(SUBS_KEY);
const subnames = collection.subscriptions;
if (subnames.length > 0) {
const sub = findByName(allSubs, subnames[0]);
let flowInfo;
if (
sub.source !== 'local' ||
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
@@ -395,16 +414,13 @@ async function downloadCollection(req, res) {
}
}
if (!$arguments.noFlow) {
flowInfo = await getFlowHeaders(
subUserInfoOfSub = await getFlowHeaders(
$arguments?.insecure ? `${url}#insecure` : url,
$arguments.flowUserAgent,
undefined,
proxy || sub.proxy || collection.proxy,
$arguments.flowUrl,
);
if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
}
} catch (err) {
$.error(
@@ -415,13 +431,61 @@ async function downloadCollection(req, res) {
}
}
if (sub.subUserinfo) {
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
);
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`组合订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
subUserInfoOfSub = [subUserInfo, subUserInfoOfSub]
.filter((i) => i)
.join('; ');
}
}
$.info(`组合订阅 ${name} 透传的的流量信息: ${subUserInfoOfSub}`);
let subUserInfoOfCol;
if (/^https?:\/\//.test(collection.subUserinfo)) {
try {
subUserInfoOfCol = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || collection.proxy,
collection.subUserinfo,
);
} catch (e) {
$.error(
`组合订阅 ${name} 使用自定义流量链接 ${
collection.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfoOfCol = collection.subUserinfo;
}
res.set(
'subscription-userinfo',
[subUserInfoOfCol, subUserInfoOfSub]
.filter((i) => i)
.join('; '),
);
if (platform === 'JSON') {
if (resultFormat === 'nezha') {
output = nezhaTransform(output);

View File

@@ -62,6 +62,7 @@ async function getFile(req, res) {
mergeSources,
ignoreFailedRemoteFile,
proxy,
noCache,
} = req.query;
let $options = {};
if (req.query.$options) {
@@ -113,6 +114,9 @@ async function getFile(req, res) {
ignoreFailedRemoteFile = decodeURIComponent(ignoreFailedRemoteFile);
$.info(`指定忽略失败的远程文件: ${ignoreFailedRemoteFile}`);
}
if (noCache) {
$.info(`指定不使用缓存: ${noCache}`);
}
const allFiles = $.read(FILES_KEY);
const file = findByName(allFiles, name);
@@ -128,6 +132,7 @@ async function getFile(req, res) {
ignoreFailedRemoteFile,
$options,
proxy,
noCache,
});
try {
@@ -179,7 +184,7 @@ async function getFile(req, res) {
);
}
} else {
$.error(`🌍 Sub-Store 下载文件失败`, `❌ 未找到文件:${name}`);
$.error(`🌍 Sub-Store 下载文件失败\n❌ 未找到文件:${name}`);
failed(
res,
new ResourceNotFoundError(

View File

@@ -114,6 +114,10 @@ async function compareSub(req, res) {
sub.ua,
undefined,
sub.proxy,
undefined,
undefined,
undefined,
true,
);
} catch (err) {
errors[url] = err;
@@ -219,6 +223,10 @@ async function compareCollection(req, res) {
sub.ua,
undefined,
sub.proxy,
undefined,
undefined,
undefined,
true,
);
} catch (err) {
errors[url] = err;

View File

@@ -57,9 +57,29 @@ async function getFlowInfo(req, res) {
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
) {
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
try {
success(res, {
...parseFlowHeaders(sub.subUserinfo),
...parseFlowHeaders(subUserInfo),
});
} catch (e) {
$.error(
@@ -149,9 +169,29 @@ async function getFlowInfo(req, res) {
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
});
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
const result = {
...parseFlowHeaders(
[sub.subUserinfo, flowHeaders].filter((i) => i).join('; '),
[subUserInfo, flowHeaders].filter((i) => i).join('; '),
),
};
if (remainingDays != null) {

View File

@@ -74,6 +74,7 @@ async function produceArtifact({
undefined,
awaitCustomCache,
noCache,
true,
);
} catch (err) {
errors[url] = err;
@@ -122,6 +123,7 @@ async function produceArtifact({
undefined,
awaitCustomCache,
noCache,
true,
);
} catch (err) {
errors[url] = err;
@@ -243,6 +245,7 @@ async function produceArtifact({
undefined,
undefined,
noCache,
true,
);
} catch (err) {
errors[url] = err;

View File

@@ -11,6 +11,10 @@ import {
validCheck,
} from '@/utils/flow';
import $ from '@/core/app';
import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors';
const clashPreprocessor = PROXY_PREPROCESSORS.find(
(processor) => processor.name === 'Clash Pre-processor',
);
const tasks = new Map();
@@ -22,6 +26,7 @@ export default async function download(
skipCustomCache,
awaitCustomCache,
noCache,
preprocess,
) {
let $arguments = {};
let url = rawUrl.replace(/#noFlow$/, '');
@@ -87,6 +92,9 @@ export default async function download(
timeout,
proxy,
true,
undefined,
undefined,
preprocess,
);
} catch (e) {
$.error(
@@ -107,6 +115,9 @@ export default async function download(
timeout,
proxy,
true,
undefined,
undefined,
preprocess,
).catch((e) => {
$.error(
`乐观缓存: URL ${url} 异步更新缓存发生错误 ${
@@ -169,10 +180,10 @@ export default async function download(
: { insecure: true }
: undefined;
$.info(
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nPreprocess: ${preprocess}\nURL: ${url}`,
);
try {
const { body, headers, statusCode } = await http.get({
let { body, headers, statusCode } = await http.get({
url,
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
@@ -193,6 +204,15 @@ export default async function download(
}
if (body.replace(/\s/g, '').length === 0)
throw new Error(new Error('远程资源内容为空'));
if (preprocess) {
try {
if (clashPreprocessor.test(body)) {
body = clashPreprocessor.parse(body);
}
} catch (e) {
$.error(`Clash Pre-processor error: ${e}`);
}
}
let shouldCache = true;
if (cacheThreshold) {
const size = body.length / 1024;

View File

@@ -167,6 +167,9 @@ export async function getFlowHeaders(
flowInfo = getFlowField(headers);
}
}
if (flowInfo) {
flowInfo = flowInfo.trim();
}
if (flowInfo) {
headersResourceCache.set(id, flowInfo);
}

View File

@@ -17,6 +17,7 @@ const ISOFlags = {
'🇧🇪': ['BE', 'BEL'],
'🇧🇬': ['BG', 'BGR'],
'🇧🇭': ['BH', 'BHR'],
'🇧🇴': ['BO', 'BOL'],
'🇧🇷': ['BR', 'BRA'],
'🇧🇾': ['BY', 'BLR'],
'🇨🇦': ['CA', 'CAN'],
@@ -38,6 +39,7 @@ const ISOFlags = {
'🇬🇧': ['GB', 'GBR', 'UK'],
'🇬🇪': ['GE', 'GEO'],
'🇬🇷': ['GR', 'GRC'],
'🇬🇹': ['GT', 'GTM'],
'🇭🇰': ['HK', 'HKG', 'HKT', 'HKBN', 'HGC', 'WTT', 'CMI'],
'🇭🇷': ['HR', 'HRV'],
'🇭🇺': ['HU', 'HUN'],
@@ -141,6 +143,7 @@ export function getFlag(name) {
'🇧🇭': ['Bahrain', '巴林'],
'🇧🇷': ['Brazil', '巴西', '圣保罗'],
'🇧🇾': ['Belarus', '白俄罗斯', '白俄'],
'🇧🇴': ['Bolivia', '玻利维亚'],
'🇨🇦': [
'Canada',
'加拿大',
@@ -191,6 +194,7 @@ export function getFlag(name) {
],
'🇬🇪': ['Georgia', '格鲁吉亚', '格魯吉亞'],
'🇬🇷': ['Greece', '希腊', '希臘'],
'🇬🇹': ['Guatemala', '危地马拉'],
'🇭🇰': [
'Hongkong',
'香港',

View File

@@ -165,6 +165,20 @@ function operator(proxies = [], targetPlatform, context) {
// 若不存在 `source._collection`, 说明输出结果为单条订阅, 脚本设置在此单条订阅上
// 这个历史遗留原因, 是有点复杂. 提供一个例子, 用来取当前脚本所在的组合订阅或单条订阅名称
// let name = ''
// for (const [key, value] of Object.entries(env.source)) {
// if (!key.startsWith('_')) {
// name = value.displayName || value.name
// break
// }
// }
// if (!name) {
// const collection = env.source._collection
// name = collection.displayName || collection.name
// }
// 1. 输出单条订阅 sub-1 时, 该单条订阅中的脚本上下文为:
// {
// "source": {