mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 00:52:40 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff1dacda87 | ||
|
|
9426f128c4 | ||
|
|
ebc7173c95 | ||
|
|
dd4e0cef68 | ||
|
|
b1618c3803 | ||
|
|
1b4c046b75 | ||
|
|
41034ceb46 | ||
|
|
6efb19c856 | ||
|
|
2cd30dfe68 | ||
|
|
d53947d820 | ||
|
|
7e75031e92 | ||
|
|
4a07c02dc1 | ||
|
|
95d6688539 | ||
|
|
a23e2ffcd6 | ||
|
|
fda1252d0e | ||
|
|
62c5c2e15b | ||
|
|
ffabcc9391 | ||
|
|
0825f15d04 | ||
|
|
fbf6b5ce6e | ||
|
|
3eb0816c88 | ||
|
|
8fc755ff02 | ||
|
|
6d3d6fa1b3 | ||
|
|
4ef4431c2c | ||
|
|
5058662651 | ||
|
|
f9d120bac3 | ||
|
|
72a445ae33 | ||
|
|
5e2a87e250 | ||
|
|
71fc9affbf | ||
|
|
6f82294c49 | ||
|
|
7c398ba51c | ||
|
|
7002eee88d | ||
|
|
bd21d58fe7 | ||
|
|
2ea46dcbf1 | ||
|
|
4a2a2297f6 | ||
|
|
07d5a913f0 | ||
|
|
421df8f0d4 |
@@ -26,13 +26,13 @@ Core functionalities:
|
|||||||
|
|
||||||
### Supported Input Formats
|
### Supported Input Formats
|
||||||
|
|
||||||
> ⚠️ Do not use `Shadowrocket` to export URI and then import it as input. It is not a standard URI.
|
> ⚠️ Do not use `Shadowrocket` or `NekoBox` to export URI and then import it as input. The URIs exported in this way may not be standard URIs.
|
||||||
|
|
||||||
- [x] Proxy URI Scheme(`socks5`, `socks5+tls`, `http`, `https`(it's ok))
|
- [x] Proxy URI Scheme(`socks5`, `socks5+tls`, `http`, `https`(it's ok))
|
||||||
|
|
||||||
example: `socks5+tls://user:pass@ip:port#name`
|
example: `socks5+tls://user:pass@ip:port#name`
|
||||||
|
|
||||||
- [x] URI(SS, SSR, VMess, VLESS, Trojan, Hysteria, Hysteria 2, TUIC v5, WireGuard)
|
- [x] URI(SOCKS, SS, SSR, VMess, VLESS, Trojan, Hysteria, Hysteria 2, TUIC v5, WireGuard)
|
||||||
- [x] Clash Proxies YAML
|
- [x] Clash Proxies YAML
|
||||||
- [x] Clash Proxy JSON(single line)
|
- [x] Clash Proxy JSON(single line)
|
||||||
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
|
- [x] QX (SS, SSR, VMess, Trojan, HTTP, SOCKS5, VLESS)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* ╚════██║██║ ██║██╔══██╗╚════╝╚════██║ ██║ ██║ ██║██╔══██╗██╔══╝
|
* ╚════██║██║ ██║██╔══██╗╚════╝╚════██║ ██║ ██║ ██║██╔══██╗██╔══╝
|
||||||
* ███████║╚██████╔╝██████╔╝ ███████║ ██║ ╚██████╔╝██║ ██║███████╗
|
* ███████║╚██████╔╝██████╔╝ ███████║ ██║ ╚██████╔╝██║ ██║███████╗
|
||||||
* ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
* ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
||||||
* Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket!
|
* Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket!
|
||||||
* @updated: <%= updated %>
|
* @updated: <%= updated %>
|
||||||
* @version: <%= pkg.version %>
|
* @version: <%= pkg.version %>
|
||||||
* @author: Peng-YM
|
* @author: Peng-YM
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.16.30",
|
"version": "2.17.0",
|
||||||
"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": {
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
isIPv4,
|
isIPv4,
|
||||||
isIPv6,
|
isIPv6,
|
||||||
isValidPortNumber,
|
isValidPortNumber,
|
||||||
|
isValidUUID,
|
||||||
isNotBlank,
|
isNotBlank,
|
||||||
ipAddress,
|
ipAddress,
|
||||||
getRandomPort,
|
getRandomPort,
|
||||||
@@ -21,6 +22,8 @@ import { findByName } from '@/utils/database';
|
|||||||
import { produceArtifact } from '@/restful/sync';
|
import { produceArtifact } from '@/restful/sync';
|
||||||
import { getFlag, removeFlag, getISO, MMDB } from '@/utils/geo';
|
import { getFlag, removeFlag, getISO, MMDB } from '@/utils/geo';
|
||||||
import Gist from '@/utils/gist';
|
import Gist from '@/utils/gist';
|
||||||
|
import { isPresent } from './producers/utils';
|
||||||
|
import { doh } from '@/utils/dns';
|
||||||
|
|
||||||
function preprocess(raw) {
|
function preprocess(raw) {
|
||||||
for (const processor of PROXY_PREPROCESSORS) {
|
for (const processor of PROXY_PREPROCESSORS) {
|
||||||
@@ -75,7 +78,16 @@ function parse(raw) {
|
|||||||
$.error(`Failed to parse line: ${line}`);
|
$.error(`Failed to parse line: ${line}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return proxies;
|
return proxies.filter((proxy) => {
|
||||||
|
if (['vless', 'vmess'].includes(proxy.type)) {
|
||||||
|
const isProxyUUIDValid = isValidUUID(proxy.uuid);
|
||||||
|
if (!isProxyUUIDValid) {
|
||||||
|
$.error(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||||
|
}
|
||||||
|
// return isProxyUUIDValid;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processFn(
|
async function processFn(
|
||||||
@@ -214,10 +226,22 @@ function produce(proxies, targetPlatform, type, opts = {}) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// filter unsupported proxies
|
// filter unsupported proxies
|
||||||
proxies = proxies.filter(
|
proxies = proxies.filter((proxy) => {
|
||||||
(proxy) =>
|
// 检查代理是否支持目标平台
|
||||||
!(proxy.supported && proxy.supported[targetPlatform] === false),
|
if (proxy.supported && proxy.supported[targetPlatform] === false) {
|
||||||
);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对于 vless 和 vmess 代理,需要额外验证 UUID
|
||||||
|
if (['vless', 'vmess'].includes(proxy.type)) {
|
||||||
|
const isProxyUUIDValid = isValidUUID(proxy.uuid);
|
||||||
|
if (!isProxyUUIDValid)
|
||||||
|
$.error(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||||
|
// return isProxyUUIDValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
proxies = proxies.map((proxy) => {
|
proxies = proxies.map((proxy) => {
|
||||||
proxy._resolved = proxy.resolved;
|
proxy._resolved = proxy.resolved;
|
||||||
@@ -303,6 +327,8 @@ export const ProxyUtils = {
|
|||||||
MMDB,
|
MMDB,
|
||||||
Gist,
|
Gist,
|
||||||
download,
|
download,
|
||||||
|
isValidUUID,
|
||||||
|
doh,
|
||||||
};
|
};
|
||||||
|
|
||||||
function tryParse(parser, line) {
|
function tryParse(parser, line) {
|
||||||
@@ -400,9 +426,14 @@ function lastParse(proxy) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
['trojan', 'tuic', 'hysteria', 'hysteria2', 'juicity'].includes(
|
[
|
||||||
proxy.type,
|
'trojan',
|
||||||
)
|
'tuic',
|
||||||
|
'hysteria',
|
||||||
|
'hysteria2',
|
||||||
|
'juicity',
|
||||||
|
'anytls',
|
||||||
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
proxy.tls = true;
|
proxy.tls = true;
|
||||||
}
|
}
|
||||||
@@ -572,6 +603,20 @@ function lastParse(proxy) {
|
|||||||
if (!proxy['tls-fingerprint'] && caStr) {
|
if (!proxy['tls-fingerprint'] && caStr) {
|
||||||
proxy['tls-fingerprint'] = rs.generateFingerprint(caStr);
|
proxy['tls-fingerprint'] = rs.generateFingerprint(caStr);
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
['shadowsocks'].includes(proxy.type) &&
|
||||||
|
isPresent(proxy, 'shadow-tls-password')
|
||||||
|
) {
|
||||||
|
proxy.plugin = 'shadow-tls';
|
||||||
|
proxy['plugin-opts'] = {
|
||||||
|
host: proxy['shadow-tls-sni'],
|
||||||
|
password: proxy['shadow-tls-password'],
|
||||||
|
version: proxy['shadow-tls-version'],
|
||||||
|
};
|
||||||
|
delete proxy['shadow-tls-sni'];
|
||||||
|
delete proxy['shadow-tls-password'];
|
||||||
|
delete proxy['shadow-tls-version'];
|
||||||
|
}
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,46 @@ function URI_PROXY() {
|
|||||||
};
|
};
|
||||||
return { name, test, parse };
|
return { name, test, parse };
|
||||||
}
|
}
|
||||||
|
function URI_SOCKS() {
|
||||||
|
const name = 'URI SOCKS Parser';
|
||||||
|
const test = (line) => {
|
||||||
|
return /^socks:\/\//.test(line);
|
||||||
|
};
|
||||||
|
const parse = (line) => {
|
||||||
|
// parse url
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
let [__, type, auth, server, port, query, name] = line.match(
|
||||||
|
/^(socks)?:\/\/(?:(.*)@)?(.*?)(?::(\d+?))?(\?.*?)?(?:#(.*?))?$/,
|
||||||
|
);
|
||||||
|
if (port) {
|
||||||
|
port = parseInt(port, 10);
|
||||||
|
} else {
|
||||||
|
$.error(`port is not present in line: ${line}`);
|
||||||
|
throw new Error(`port is not present in line: ${line}`);
|
||||||
|
}
|
||||||
|
let username, password;
|
||||||
|
if (auth) {
|
||||||
|
const parsed = Base64.decode(decodeURIComponent(auth)).split(':');
|
||||||
|
username = parsed[0];
|
||||||
|
password = parsed[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxy = {
|
||||||
|
name:
|
||||||
|
name != null
|
||||||
|
? decodeURIComponent(name)
|
||||||
|
: `${type} ${server}:${port}`,
|
||||||
|
type: 'socks5',
|
||||||
|
server,
|
||||||
|
port,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
};
|
||||||
|
|
||||||
|
return proxy;
|
||||||
|
};
|
||||||
|
return { name, test, parse };
|
||||||
|
}
|
||||||
// Parse SS URI format (only supports new SIP002, legacy format is depreciated).
|
// Parse SS URI format (only supports new SIP002, legacy format is depreciated).
|
||||||
// reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme
|
// reference: https://github.com/shadowsocks/shadowsocks-org/wiki/SIP002-URI-Scheme
|
||||||
function URI_SS() {
|
function URI_SS() {
|
||||||
@@ -113,6 +152,7 @@ function URI_SS() {
|
|||||||
query = parsed[2];
|
query = parsed[2];
|
||||||
}
|
}
|
||||||
content = Base64.decode(content);
|
content = Base64.decode(content);
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
if (/(&|\?)v2ray-plugin=/.test(query)) {
|
if (/(&|\?)v2ray-plugin=/.test(query)) {
|
||||||
const parsed = query.match(/(&|\?)v2ray-plugin=(.*?)(&|$)/);
|
const parsed = query.match(/(&|\?)v2ray-plugin=(.*?)(&|$)/);
|
||||||
@@ -126,8 +166,11 @@ function URI_SS() {
|
|||||||
}
|
}
|
||||||
content = `${content}${query}`;
|
content = `${content}${query}`;
|
||||||
}
|
}
|
||||||
userInfoStr = content.split('@')[0];
|
userInfoStr = content.match(/(^.*)@/)?.[1];
|
||||||
serverAndPortArray = content.match(/@([^/]*)(\/|$)/);
|
serverAndPortArray = content.match(/@([^/@]*)(\/|$)/);
|
||||||
|
} else if (content.includes('?')) {
|
||||||
|
const parsed = content.match(/(\?.*)$/);
|
||||||
|
query = parsed[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverAndPort = serverAndPortArray[1];
|
const serverAndPort = serverAndPortArray[1];
|
||||||
@@ -146,11 +189,12 @@ function URI_SS() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// handle obfs
|
// handle obfs
|
||||||
const idx = content.indexOf('?plugin=');
|
const pluginMatch = content.match(/[?&]plugin=([^&]+)/);
|
||||||
if (idx !== -1) {
|
const shadowTlsMatch = content.match(/[?&]shadow-tls=([^&]+)/);
|
||||||
|
|
||||||
|
if (pluginMatch) {
|
||||||
const pluginInfo = (
|
const pluginInfo = (
|
||||||
'plugin=' +
|
'plugin=' + decodeURIComponent(pluginMatch[1])
|
||||||
decodeURIComponent(content.split('?plugin=')[1].split('&')[0])
|
|
||||||
).split(';');
|
).split(';');
|
||||||
const params = {};
|
const params = {};
|
||||||
for (const item of pluginInfo) {
|
for (const item of pluginInfo) {
|
||||||
@@ -175,12 +219,41 @@ function URI_SS() {
|
|||||||
tls: getIfPresent(params.tls),
|
tls: getIfPresent(params.tls),
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
case 'shadow-tls': {
|
||||||
|
proxy.plugin = 'shadow-tls';
|
||||||
|
const version = getIfNotBlank(params['version']);
|
||||||
|
proxy['plugin-opts'] = {
|
||||||
|
host: getIfNotBlank(params['host']),
|
||||||
|
password: getIfNotBlank(params['password']),
|
||||||
|
version: version ? parseInt(version, 10) : undefined,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unsupported plugin option: ${params.plugin}`,
|
`Unsupported plugin option: ${params.plugin}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Shadowrocket
|
||||||
|
if (shadowTlsMatch) {
|
||||||
|
const params = JSON.parse(Base64.decode(shadowTlsMatch[1]));
|
||||||
|
const version = getIfNotBlank(params['version']);
|
||||||
|
const address = getIfNotBlank(params['address']);
|
||||||
|
const port = getIfNotBlank(params['port']);
|
||||||
|
proxy.plugin = 'shadow-tls';
|
||||||
|
proxy['plugin-opts'] = {
|
||||||
|
host: getIfNotBlank(params['host']),
|
||||||
|
password: getIfNotBlank(params['password']),
|
||||||
|
version: version ? parseInt(version, 10) : undefined,
|
||||||
|
};
|
||||||
|
if (address) {
|
||||||
|
proxy.server = address;
|
||||||
|
}
|
||||||
|
if (port) {
|
||||||
|
proxy.port = parseInt(port, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (/(&|\?)uot=(1|true)/i.test(query)) {
|
if (/(&|\?)uot=(1|true)/i.test(query)) {
|
||||||
proxy['udp-over-tcp'] = true;
|
proxy['udp-over-tcp'] = true;
|
||||||
}
|
}
|
||||||
@@ -787,8 +860,11 @@ function URI_TUIC() {
|
|||||||
const parse = (line) => {
|
const parse = (line) => {
|
||||||
line = line.split(/tuic:\/\//)[1];
|
line = line.split(/tuic:\/\//)[1];
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
let [__, uuid, password, server, ___, port, ____, addons = '', name] =
|
let [__, auth, server, port, addons = '', name] =
|
||||||
/^(.*?):(.*?)@(.*?)(:(\d+))?\/?(\?(.*?))?(?:#(.*?))?$/.exec(line);
|
/^(.*?)@(.*?)(?::(\d+))?\/?(?:\?(.*?))?(?:#(.*?))?$/.exec(line);
|
||||||
|
auth = decodeURIComponent(auth);
|
||||||
|
let [uuid, ...passwordParts] = auth.split(':');
|
||||||
|
let password = passwordParts.join(':');
|
||||||
port = parseInt(`${port}`, 10);
|
port = parseInt(`${port}`, 10);
|
||||||
if (isNaN(port)) {
|
if (isNaN(port)) {
|
||||||
port = 443;
|
port = 443;
|
||||||
@@ -810,12 +886,14 @@ function URI_TUIC() {
|
|||||||
|
|
||||||
for (const addon of addons.split('&')) {
|
for (const addon of addons.split('&')) {
|
||||||
let [key, value] = addon.split('=');
|
let [key, value] = addon.split('=');
|
||||||
key = key.replace(/_/, '-');
|
key = key.replace(/_/g, '-');
|
||||||
value = decodeURIComponent(value);
|
value = decodeURIComponent(value);
|
||||||
if (['alpn'].includes(key)) {
|
if (['alpn'].includes(key)) {
|
||||||
proxy[key] = value ? value.split(',') : undefined;
|
proxy[key] = value ? value.split(',') : undefined;
|
||||||
} else if (['allow-insecure'].includes(key)) {
|
} else if (['allow-insecure'].includes(key)) {
|
||||||
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(value);
|
proxy['skip-cert-verify'] = /(TRUE)|1/i.test(value);
|
||||||
|
} else if (['fast-open'].includes(key)) {
|
||||||
|
proxy.tfo = true;
|
||||||
} else if (['disable-sni', 'reduce-rtt'].includes(key)) {
|
} else if (['disable-sni', 'reduce-rtt'].includes(key)) {
|
||||||
proxy[key] = /(TRUE)|1/i.test(value);
|
proxy[key] = /(TRUE)|1/i.test(value);
|
||||||
} else {
|
} else {
|
||||||
@@ -953,6 +1031,7 @@ function Clash_All() {
|
|||||||
const proxy = JSON.parse(line);
|
const proxy = JSON.parse(line);
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
|
'anytls',
|
||||||
'mieru',
|
'mieru',
|
||||||
'juicity',
|
'juicity',
|
||||||
'ss',
|
'ss',
|
||||||
@@ -1455,6 +1534,7 @@ function isIP(ip) {
|
|||||||
|
|
||||||
export default [
|
export default [
|
||||||
URI_PROXY(),
|
URI_PROXY(),
|
||||||
|
URI_SOCKS(),
|
||||||
URI_SS(),
|
URI_SS(),
|
||||||
URI_SSR(),
|
URI_SSR(),
|
||||||
URI_VMess(),
|
URI_VMess(),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ function Base64Encoded() {
|
|||||||
const keys = [
|
const keys = [
|
||||||
'dm1lc3M', // vmess
|
'dm1lc3M', // vmess
|
||||||
'c3NyOi8v', // ssr://
|
'c3NyOi8v', // ssr://
|
||||||
|
'c29ja3M6Ly', // socks://
|
||||||
'dHJvamFu', // trojan
|
'dHJvamFu', // trojan
|
||||||
'c3M6Ly', // ss:/
|
'c3M6Ly', // ss:/
|
||||||
'c3NkOi8v', // ssd://
|
'c3NkOi8v', // ssd://
|
||||||
@@ -62,7 +63,7 @@ function Clash() {
|
|||||||
// 防止 VLESS节点 reality-opts 选项中的 short-id 被解析成 Infinity
|
// 防止 VLESS节点 reality-opts 选项中的 short-id 被解析成 Infinity
|
||||||
// 匹配 short-id 冒号后面的值(包含空格和引号)
|
// 匹配 short-id 冒号后面的值(包含空格和引号)
|
||||||
const afterReplace = raw.replace(
|
const afterReplace = raw.replace(
|
||||||
/short-id:([ ]*[^,\n}]*)/g,
|
/short-id:([ \t]*[^#\n,}]*)/g,
|
||||||
(matched, value) => {
|
(matched, value) => {
|
||||||
const afterTrim = value.trim();
|
const afterTrim = value.trim();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
validCheck,
|
validCheck,
|
||||||
flowTransfer,
|
flowTransfer,
|
||||||
getRmainingDays,
|
getRmainingDays,
|
||||||
|
normalizeFlowHeader,
|
||||||
} from '@/utils/flow';
|
} from '@/utils/flow';
|
||||||
|
|
||||||
function isObject(item) {
|
function isObject(item) {
|
||||||
@@ -365,22 +366,35 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
|
|||||||
if (output?.$file?.type === 'mihomoProfile') {
|
if (output?.$file?.type === 'mihomoProfile') {
|
||||||
try {
|
try {
|
||||||
let patch = YAML.safeLoad(script);
|
let patch = YAML.safeLoad(script);
|
||||||
if (typeof patch !== 'object') patch = {};
|
let config;
|
||||||
|
if (output?.$content) {
|
||||||
|
try {
|
||||||
|
config = YAML.safeLoad(output?.$content);
|
||||||
|
} catch (e) {
|
||||||
|
$.error(e.message ?? e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if (typeof patch !== 'object') patch = {};
|
||||||
|
if (typeof patch !== 'object')
|
||||||
|
throw new Error('patch is not an object');
|
||||||
output.$content = ProxyUtils.yaml.safeDump(
|
output.$content = ProxyUtils.yaml.safeDump(
|
||||||
deepMerge(
|
deepMerge(
|
||||||
{
|
config ||
|
||||||
proxies: await produceArtifact({
|
(output?.$file?.sourceType === 'none'
|
||||||
type:
|
? {}
|
||||||
output?.$file?.sourceType ||
|
: {
|
||||||
'collection',
|
proxies: await produceArtifact({
|
||||||
name: output?.$file?.sourceName,
|
type:
|
||||||
platform: 'mihomo',
|
output?.$file?.sourceType ||
|
||||||
produceType: 'internal',
|
'collection',
|
||||||
produceOpts: {
|
name: output?.$file?.sourceName,
|
||||||
'delete-underscore-fields': true,
|
platform: 'mihomo',
|
||||||
},
|
produceType: 'internal',
|
||||||
}),
|
produceOpts: {
|
||||||
},
|
'delete-underscore-fields': true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
patch,
|
patch,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -411,7 +425,15 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
|
|||||||
if($file.type === 'mihomoProfile') {
|
if($file.type === 'mihomoProfile') {
|
||||||
${script}
|
${script}
|
||||||
if(typeof main === 'function') {
|
if(typeof main === 'function') {
|
||||||
const config = {
|
let config;
|
||||||
|
if ($content) {
|
||||||
|
try {
|
||||||
|
config = ProxyUtils.yaml.safeLoad($content);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e.message ?? e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$content = ProxyUtils.yaml.safeDump(await main(config || ($file.sourceType === 'none' ? {} : {
|
||||||
proxies: await produceArtifact({
|
proxies: await produceArtifact({
|
||||||
type: $file.sourceType || 'collection',
|
type: $file.sourceType || 'collection',
|
||||||
name: $file.sourceName,
|
name: $file.sourceName,
|
||||||
@@ -421,8 +443,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
|
|||||||
'delete-underscore-fields': true
|
'delete-underscore-fields': true
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
}
|
})))
|
||||||
$content = ProxyUtils.yaml.safeDump(await main(config))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
${script}
|
${script}
|
||||||
@@ -828,7 +849,12 @@ function UselessFilter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter by regions
|
// filter by regions
|
||||||
function RegionFilter(regions) {
|
function RegionFilter(input) {
|
||||||
|
let regions = input?.value || input;
|
||||||
|
if (!Array.isArray(regions)) {
|
||||||
|
regions = [];
|
||||||
|
}
|
||||||
|
const keep = input?.keep ?? true;
|
||||||
const REGION_MAP = {
|
const REGION_MAP = {
|
||||||
HK: '🇭🇰',
|
HK: '🇭🇰',
|
||||||
TW: '🇹🇼',
|
TW: '🇹🇼',
|
||||||
@@ -845,7 +871,8 @@ function RegionFilter(regions) {
|
|||||||
// this would be high memory usage
|
// this would be high memory usage
|
||||||
return proxies.map((proxy) => {
|
return proxies.map((proxy) => {
|
||||||
const flag = getFlag(proxy.name);
|
const flag = getFlag(proxy.name);
|
||||||
return regions.some((r) => REGION_MAP[r] === flag);
|
const selected = regions.some((r) => REGION_MAP[r] === flag);
|
||||||
|
return keep ? selected : !selected;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -877,11 +904,19 @@ function buildRegex(str, ...options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// filter by proxy types
|
// filter by proxy types
|
||||||
function TypeFilter(types) {
|
function TypeFilter(input) {
|
||||||
|
let types = input?.value || input;
|
||||||
|
if (!Array.isArray(types)) {
|
||||||
|
types = [];
|
||||||
|
}
|
||||||
|
const keep = input?.keep ?? true;
|
||||||
return {
|
return {
|
||||||
name: 'Type Filter',
|
name: 'Type Filter',
|
||||||
func: (proxies) => {
|
func: (proxies) => {
|
||||||
return proxies.map((proxy) => types.some((t) => proxy.type === t));
|
return proxies.map((proxy) => {
|
||||||
|
const selected = types.some((t) => proxy.type === t);
|
||||||
|
return keep ? selected : !selected;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1081,6 +1116,7 @@ function createDynamicFunction(name, script, $arguments, $options) {
|
|||||||
flowTransfer,
|
flowTransfer,
|
||||||
validCheck,
|
validCheck,
|
||||||
getRmainingDays,
|
getRmainingDays,
|
||||||
|
normalizeFlowHeader,
|
||||||
};
|
};
|
||||||
if ($.env.isLoon) {
|
if ($.env.isLoon) {
|
||||||
return new Function(
|
return new Function(
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ export default function Clash_Producer() {
|
|||||||
'hysteria',
|
'hysteria',
|
||||||
'hysteria2',
|
'hysteria2',
|
||||||
'juicity',
|
'juicity',
|
||||||
|
'anytls',
|
||||||
].includes(proxy.type)
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
delete proxy.tls;
|
delete proxy.tls;
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ export default function ClashMeta_Producer() {
|
|||||||
password: proxy['shadow-tls-password'],
|
password: proxy['shadow-tls-password'],
|
||||||
version: proxy['shadow-tls-version'],
|
version: proxy['shadow-tls-version'],
|
||||||
};
|
};
|
||||||
|
delete proxy['shadow-tls-password'];
|
||||||
|
delete proxy['shadow-tls-sni'];
|
||||||
|
delete proxy['shadow-tls-version'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +163,7 @@ export default function ClashMeta_Producer() {
|
|||||||
'hysteria',
|
'hysteria',
|
||||||
'hysteria2',
|
'hysteria2',
|
||||||
'juicity',
|
'juicity',
|
||||||
|
'anytls',
|
||||||
].includes(proxy.type)
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
delete proxy.tls;
|
delete proxy.tls;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import { isPresent } from './utils';
|
||||||
|
|
||||||
export default function Egern_Producer() {
|
export default function Egern_Producer() {
|
||||||
const type = 'ALL';
|
const type = 'ALL';
|
||||||
const produce = (proxies, type, opts = {}) => {
|
const produce = (proxies, type) => {
|
||||||
// https://egernapp.com/zh-CN/docs/configuration/proxies
|
// https://egernapp.com/zh-CN/docs/configuration/proxies
|
||||||
const list = proxies
|
const list = proxies
|
||||||
.filter((proxy) => {
|
.filter((proxy) => {
|
||||||
@@ -71,6 +73,7 @@ export default function Egern_Producer() {
|
|||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.map((proxy) => {
|
.map((proxy) => {
|
||||||
|
const original = { ...proxy };
|
||||||
if (proxy.tls && !proxy.sni) {
|
if (proxy.tls && !proxy.sni) {
|
||||||
proxy.sni = proxy.server;
|
proxy.sni = proxy.server;
|
||||||
}
|
}
|
||||||
@@ -184,6 +187,7 @@ export default function Egern_Producer() {
|
|||||||
websocket: proxy.websocket,
|
websocket: proxy.websocket,
|
||||||
};
|
};
|
||||||
} else if (proxy.type === 'vmess') {
|
} else if (proxy.type === 'vmess') {
|
||||||
|
// Egern:传输层,支持 ws/wss/http1/http2/tls,不配置则为 tcp
|
||||||
let security = proxy.cipher;
|
let security = proxy.cipher;
|
||||||
if (
|
if (
|
||||||
security &&
|
security &&
|
||||||
@@ -212,9 +216,11 @@ export default function Egern_Producer() {
|
|||||||
};
|
};
|
||||||
} else if (proxy.network === 'http') {
|
} else if (proxy.network === 'http') {
|
||||||
proxy.transport = {
|
proxy.transport = {
|
||||||
http: {
|
http1: {
|
||||||
method: proxy['http-opts']?.method,
|
method: proxy['http-opts']?.method,
|
||||||
path: proxy['http-opts']?.path,
|
path: Array.isArray(proxy['http-opts']?.path)
|
||||||
|
? proxy['http-opts']?.path[0]
|
||||||
|
: proxy['http-opts']?.path,
|
||||||
headers: {
|
headers: {
|
||||||
Host: Array.isArray(
|
Host: Array.isArray(
|
||||||
proxy['http-opts']?.headers?.Host,
|
proxy['http-opts']?.headers?.Host,
|
||||||
@@ -225,9 +231,29 @@ export default function Egern_Producer() {
|
|||||||
skip_tls_verify: proxy['skip-cert-verify'],
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else if (proxy.network === 'tcp' || !proxy.network) {
|
} else if (proxy.network === 'h2') {
|
||||||
proxy.transport = {
|
proxy.transport = {
|
||||||
[proxy.tls ? 'tls' : 'tcp']: {
|
http2: {
|
||||||
|
method: proxy['h2-opts']?.method,
|
||||||
|
path: Array.isArray(proxy['h2-opts']?.path)
|
||||||
|
? proxy['h2-opts']?.path[0]
|
||||||
|
: proxy['h2-opts']?.path,
|
||||||
|
headers: {
|
||||||
|
Host: Array.isArray(
|
||||||
|
proxy['h2-opts']?.headers?.Host,
|
||||||
|
)
|
||||||
|
? proxy['h2-opts']?.headers?.Host[0]
|
||||||
|
: proxy['h2-opts']?.headers?.Host,
|
||||||
|
},
|
||||||
|
skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
(proxy.network === 'tcp' || !proxy.network) &&
|
||||||
|
proxy.tls
|
||||||
|
) {
|
||||||
|
proxy.transport = {
|
||||||
|
tls: {
|
||||||
sni: proxy.tls ? proxy.sni : undefined,
|
sni: proxy.tls ? proxy.sni : undefined,
|
||||||
skip_tls_verify: proxy.tls
|
skip_tls_verify: proxy.tls
|
||||||
? proxy['skip-cert-verify']
|
? proxy['skip-cert-verify']
|
||||||
@@ -269,7 +295,9 @@ export default function Egern_Producer() {
|
|||||||
proxy.transport = {
|
proxy.transport = {
|
||||||
http: {
|
http: {
|
||||||
method: proxy['http-opts']?.method,
|
method: proxy['http-opts']?.method,
|
||||||
path: proxy['http-opts']?.path,
|
path: Array.isArray(proxy['http-opts']?.path)
|
||||||
|
? proxy['http-opts']?.path[0]
|
||||||
|
: proxy['http-opts']?.path,
|
||||||
headers: {
|
headers: {
|
||||||
Host: Array.isArray(
|
Host: Array.isArray(
|
||||||
proxy['http-opts']?.headers?.Host,
|
proxy['http-opts']?.headers?.Host,
|
||||||
@@ -307,6 +335,39 @@ export default function Egern_Producer() {
|
|||||||
// skip_tls_verify: proxy['skip-cert-verify'],
|
// skip_tls_verify: proxy['skip-cert-verify'],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
[
|
||||||
|
'http',
|
||||||
|
'socks5',
|
||||||
|
'ss',
|
||||||
|
'trojan',
|
||||||
|
'vless',
|
||||||
|
'vmess',
|
||||||
|
].includes(original.type)
|
||||||
|
) {
|
||||||
|
if (isPresent(original, 'shadow-tls-password')) {
|
||||||
|
if (original['shadow-tls-version'] != 3)
|
||||||
|
throw new Error(
|
||||||
|
`shadow-tls version ${original['shadow-tls-version']} is not supported`,
|
||||||
|
);
|
||||||
|
proxy.shadow_tls = {
|
||||||
|
password: original['shadow-tls-password'],
|
||||||
|
sni: original['shadow-tls-sni'],
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
['shadow-tls'].includes(original.plugin) &&
|
||||||
|
original['plugin-opts']
|
||||||
|
) {
|
||||||
|
if (original['plugin-opts'].version != 3)
|
||||||
|
throw new Error(
|
||||||
|
`shadow-tls version ${original['plugin-opts'].version} is not supported`,
|
||||||
|
);
|
||||||
|
proxy.shadow_tls = {
|
||||||
|
password: original['plugin-opts'].password,
|
||||||
|
sni: original['plugin-opts'].host,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delete proxy.subName;
|
delete proxy.subName;
|
||||||
delete proxy.collectionName;
|
delete proxy.collectionName;
|
||||||
|
|||||||
@@ -341,10 +341,9 @@ function vmess(proxy) {
|
|||||||
// udp
|
// udp
|
||||||
if (proxy.udp) {
|
if (proxy.udp) {
|
||||||
result.append(`,udp=true`);
|
result.append(`,udp=true`);
|
||||||
const ip_version =
|
|
||||||
ipVersions[proxy['ip-version']] || proxy['ip-version'];
|
|
||||||
result.appendIfPresent(`,ip-mode=${ip_version}`, 'ip-version');
|
|
||||||
}
|
}
|
||||||
|
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
|
||||||
|
result.appendIfPresent(`,ip-mode=${ip_version}`, 'ip-version');
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,10 +415,9 @@ function vless(proxy) {
|
|||||||
// udp
|
// udp
|
||||||
if (proxy.udp) {
|
if (proxy.udp) {
|
||||||
result.append(`,udp=true`);
|
result.append(`,udp=true`);
|
||||||
const ip_version =
|
|
||||||
ipVersions[proxy['ip-version']] || proxy['ip-version'];
|
|
||||||
result.appendIfPresent(`,ip-mode=${ip_version}`, 'ip-version');
|
|
||||||
}
|
}
|
||||||
|
const ip_version = ipVersions[proxy['ip-version']] || proxy['ip-version'];
|
||||||
|
result.appendIfPresent(`,ip-mode=${ip_version}`, 'ip-version');
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
import { isPresent } from '@/core/proxy-utils/producers/utils';
|
||||||
|
|
||||||
export default function ShadowRocket_Producer() {
|
export default function Shadowrocket_Producer() {
|
||||||
const type = 'ALL';
|
const type = 'ALL';
|
||||||
const produce = (proxies, type, opts = {}) => {
|
const produce = (proxies, type, opts = {}) => {
|
||||||
const list = proxies
|
const list = proxies
|
||||||
@@ -8,7 +8,7 @@ export default function ShadowRocket_Producer() {
|
|||||||
if (opts['include-unsupported-proxy']) return true;
|
if (opts['include-unsupported-proxy']) return true;
|
||||||
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
if (proxy.type === 'snell' && String(proxy.version) === '4') {
|
||||||
return false;
|
return false;
|
||||||
} else if (['mieru'].includes(proxy.type)) {
|
} else if (['mieru', 'anytls'].includes(proxy.type)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -110,6 +110,21 @@ export default function ShadowRocket_Producer() {
|
|||||||
proxy.servername = proxy.sni;
|
proxy.servername = proxy.sni;
|
||||||
delete proxy.sni;
|
delete proxy.sni;
|
||||||
}
|
}
|
||||||
|
} else if (proxy.type === 'ss') {
|
||||||
|
if (
|
||||||
|
isPresent(proxy, 'shadow-tls-password') &&
|
||||||
|
!isPresent(proxy, 'plugin')
|
||||||
|
) {
|
||||||
|
proxy.plugin = 'shadow-tls';
|
||||||
|
proxy['plugin-opts'] = {
|
||||||
|
host: proxy['shadow-tls-sni'],
|
||||||
|
password: proxy['shadow-tls-password'],
|
||||||
|
version: proxy['shadow-tls-version'],
|
||||||
|
};
|
||||||
|
delete proxy['shadow-tls-password'];
|
||||||
|
delete proxy['shadow-tls-sni'];
|
||||||
|
delete proxy['shadow-tls-version'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -163,6 +178,7 @@ export default function ShadowRocket_Producer() {
|
|||||||
'hysteria',
|
'hysteria',
|
||||||
'hysteria2',
|
'hysteria2',
|
||||||
'juicity',
|
'juicity',
|
||||||
|
'anytls',
|
||||||
].includes(proxy.type)
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
delete proxy.tls;
|
delete proxy.tls;
|
||||||
|
|||||||
@@ -641,6 +641,23 @@ const tuic5Parser = (proxy = {}) => {
|
|||||||
smuxParser(proxy.smux, parsedProxy);
|
smuxParser(proxy.smux, parsedProxy);
|
||||||
return parsedProxy;
|
return parsedProxy;
|
||||||
};
|
};
|
||||||
|
const anytlsParser = (proxy = {}) => {
|
||||||
|
const parsedProxy = {
|
||||||
|
tag: proxy.name,
|
||||||
|
type: 'anytls',
|
||||||
|
server: proxy.server,
|
||||||
|
server_port: parseInt(`${proxy.port}`, 10),
|
||||||
|
password: proxy.password,
|
||||||
|
tls: { enabled: true, server_name: proxy.server, insecure: false },
|
||||||
|
};
|
||||||
|
if (/^\d+$/.test(proxy['idle-session-check-interval']))
|
||||||
|
parsedProxy.idle_session_check_interval = `${proxy['idle-session-check-interval']}s`;
|
||||||
|
if (/^\d+$/.test(proxy['idle-session-timeout']))
|
||||||
|
parsedProxy.idle_session_timeout = `${proxy['idle-session-timeout']}s`;
|
||||||
|
detourParser(proxy, parsedProxy);
|
||||||
|
tlsParser(proxy, parsedProxy);
|
||||||
|
return parsedProxy;
|
||||||
|
};
|
||||||
|
|
||||||
const wireguardParser = (proxy = {}) => {
|
const wireguardParser = (proxy = {}) => {
|
||||||
const local_address = ['ip', 'ipv6']
|
const local_address = ['ip', 'ipv6']
|
||||||
@@ -829,6 +846,9 @@ export default function singbox_Producer() {
|
|||||||
case 'wireguard':
|
case 'wireguard':
|
||||||
list.push(wireguardParser(proxy));
|
list.push(wireguardParser(proxy));
|
||||||
break;
|
break;
|
||||||
|
case 'anytls':
|
||||||
|
list.push(anytlsParser(proxy));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Platform sing-box does not support proxy type: ${proxy.type}`,
|
`Platform sing-box does not support proxy type: ${proxy.type}`,
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ export default function Stash_Producer() {
|
|||||||
'hysteria',
|
'hysteria',
|
||||||
'hysteria2',
|
'hysteria2',
|
||||||
'juicity',
|
'juicity',
|
||||||
|
'anytls',
|
||||||
].includes(proxy.type)
|
].includes(proxy.type)
|
||||||
) {
|
) {
|
||||||
delete proxy.tls;
|
delete proxy.tls;
|
||||||
|
|||||||
@@ -433,6 +433,9 @@ function ssh(proxy) {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
function http(proxy) {
|
function http(proxy) {
|
||||||
|
if (proxy.headers && Object.keys(proxy.headers).length > 0) {
|
||||||
|
throw new Error(`headers is unsupported`);
|
||||||
|
}
|
||||||
const result = new Result(proxy);
|
const result = new Result(proxy);
|
||||||
const type = proxy.tls ? 'https' : 'http';
|
const type = proxy.tls ? 'https' : 'http';
|
||||||
result.append(`${proxy.name}=${type},${proxy.server},${proxy.port}`);
|
result.append(`${proxy.name}=${type},${proxy.server},${proxy.port}`);
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ export default function URI_Producer() {
|
|||||||
proxy.server = `[${proxy.server}]`;
|
proxy.server = `[${proxy.server}]`;
|
||||||
}
|
}
|
||||||
switch (proxy.type) {
|
switch (proxy.type) {
|
||||||
|
case 'socks5':
|
||||||
|
result = `socks://${encodeURIComponent(
|
||||||
|
Base64.encode(`${proxy.username}:${proxy.password}`),
|
||||||
|
)}@${proxy.server}:${proxy.port}#${proxy.name}`;
|
||||||
|
break;
|
||||||
case 'ss':
|
case 'ss':
|
||||||
const userinfo = `${proxy.cipher}:${proxy.password}`;
|
const userinfo = `${proxy.cipher}:${proxy.password}`;
|
||||||
result = `ss://${
|
result = `ss://${
|
||||||
@@ -54,6 +59,11 @@ export default function URI_Producer() {
|
|||||||
}${opts.tls ? ';tls' : ''}`,
|
}${opts.tls ? ';tls' : ''}`,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'shadow-tls':
|
||||||
|
result += encodeURIComponent(
|
||||||
|
`shadow-tls;host=${opts.host};password=${opts.password};version=${opts.version}`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unsupported plugin option: ${proxy.plugin}`,
|
`Unsupported plugin option: ${proxy.plugin}`,
|
||||||
@@ -511,10 +521,13 @@ export default function URI_Producer() {
|
|||||||
['disable-sni', 'reduce-rtt'].includes(key) &&
|
['disable-sni', 'reduce-rtt'].includes(key) &&
|
||||||
proxy[key]
|
proxy[key]
|
||||||
) {
|
) {
|
||||||
tuicParams.push(`${i}=1`);
|
tuicParams.push(`${i.replace(/-/g, '_')}=1`);
|
||||||
} else if (proxy[key]) {
|
} else if (proxy[key]) {
|
||||||
tuicParams.push(
|
tuicParams.push(
|
||||||
`${i}=${encodeURIComponent(proxy[key])}`,
|
`${i.replace(
|
||||||
|
/-/g,
|
||||||
|
'_',
|
||||||
|
)}=${encodeURIComponent(proxy[key])}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ async function doSync() {
|
|||||||
const files = {};
|
const files = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const valid = [];
|
||||||
const invalid = [];
|
const invalid = [];
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
const allCols = $.read(COLLECTIONS_KEY);
|
const allCols = $.read(COLLECTIONS_KEY);
|
||||||
@@ -156,19 +157,26 @@ async function doSync() {
|
|||||||
files[encodeURIComponent(artifact.name)] = {
|
files[encodeURIComponent(artifact.name)] = {
|
||||||
content: output,
|
content: output,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
valid.push(artifact.name);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(
|
$.error(
|
||||||
`同步配置 ${artifact.name} 发生错误: ${e.message ?? e}`,
|
`生成同步配置 ${artifact.name} 发生错误: ${
|
||||||
|
e.message ?? e
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
invalid.push(artifact.name);
|
invalid.push(artifact.name);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (invalid.length > 0) {
|
$.info(`${valid.length} 个同步配置生成成功: ${valid.join(', ')}`);
|
||||||
|
$.info(`${invalid.length} 个同步配置生成失败: ${invalid.join(', ')}`);
|
||||||
|
|
||||||
|
if (valid.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`同步配置 ${invalid.join(', ')} 发生错误 详情请查看日志`,
|
`同步配置 ${invalid.join(', ')} 生成失败 详情请查看日志`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +192,11 @@ async function doSync() {
|
|||||||
$.info(JSON.stringify(body, null, 2));
|
$.info(JSON.stringify(body, null, 2));
|
||||||
|
|
||||||
for (const artifact of allArtifacts) {
|
for (const artifact of allArtifacts) {
|
||||||
if (artifact.sync) {
|
if (
|
||||||
|
artifact.sync &&
|
||||||
|
artifact.source &&
|
||||||
|
valid.includes(artifact.name)
|
||||||
|
) {
|
||||||
artifact.updated = new Date().getTime();
|
artifact.updated = new Date().getTime();
|
||||||
// extract real url from gist
|
// extract real url from gist
|
||||||
let files = body.files;
|
let files = body.files;
|
||||||
@@ -212,9 +224,18 @@ async function doSync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$.write(allArtifacts, ARTIFACTS_KEY);
|
$.write(allArtifacts, ARTIFACTS_KEY);
|
||||||
$.notify('🌍 Sub-Store', '全部订阅同步成功!');
|
$.info('上传配置成功');
|
||||||
|
|
||||||
|
if (invalid.length > 0) {
|
||||||
|
$.notify(
|
||||||
|
'🌍 Sub-Store',
|
||||||
|
`同步配置成功 ${valid.length} 个, 失败 ${invalid.length} 个, 详情请查看日志`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$.notify('🌍 Sub-Store', '同步配置完成');
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.notify('🌍 Sub-Store', '同步订阅失败', `原因:${e.message ?? e}`);
|
$.notify('🌍 Sub-Store', '同步配置失败', `原因:${e.message ?? e}`);
|
||||||
$.error(`无法同步订阅配置到 Gist,原因:${e}`);
|
$.error(`无法同步配置到 Gist,原因:${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,18 @@ function getCollection(req, res) {
|
|||||||
res.set('content-type', 'application/json')
|
res.set('content-type', 'application/json')
|
||||||
.set(
|
.set(
|
||||||
'content-disposition',
|
'content-disposition',
|
||||||
`attachment; filename="${encodeURIComponent(name)}.json"`,
|
`attachment; filename="${encodeURIComponent(
|
||||||
|
`sub-store_collection_${name}_${new Date()
|
||||||
|
.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
})
|
||||||
|
.replace(/\D/g, '')}.json`,
|
||||||
|
)}"`,
|
||||||
)
|
)
|
||||||
.send(JSON.stringify(collection));
|
.send(JSON.stringify(collection));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
import { ProxyUtils } from '@/core/proxy-utils';
|
import { ProxyUtils } from '@/core/proxy-utils';
|
||||||
import { COLLECTIONS_KEY, SUBS_KEY } from '@/constants';
|
import { COLLECTIONS_KEY, SUBS_KEY } from '@/constants';
|
||||||
import { findByName } from '@/utils/database';
|
import { findByName } from '@/utils/database';
|
||||||
import { getFlowHeaders } from '@/utils/flow';
|
import { getFlowHeaders, normalizeFlowHeader } from '@/utils/flow';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
import { failed } from '@/restful/response';
|
import { failed } from '@/restful/response';
|
||||||
import { InternalServerError, ResourceNotFoundError } from '@/restful/errors';
|
import { InternalServerError, ResourceNotFoundError } from '@/restful/errors';
|
||||||
@@ -259,7 +259,10 @@ async function downloadSubscription(req, res) {
|
|||||||
$arguments.flowUrl,
|
$arguments.flowUrl,
|
||||||
);
|
);
|
||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
res.set('subscription-userinfo', flowInfo);
|
res.set(
|
||||||
|
'subscription-userinfo',
|
||||||
|
normalizeFlowHeader(flowInfo),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -293,10 +296,9 @@ async function downloadSubscription(req, res) {
|
|||||||
}
|
}
|
||||||
res.set(
|
res.set(
|
||||||
'subscription-userinfo',
|
'subscription-userinfo',
|
||||||
[subUserInfo, flowInfo]
|
normalizeFlowHeader(
|
||||||
.filter((i) => i)
|
[subUserInfo, flowInfo].filter((i) => i).join(';'),
|
||||||
.join('; ')
|
),
|
||||||
.replace(/\s*;\s*;\s*/g, ';'),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -556,7 +558,7 @@ async function downloadCollection(req, res) {
|
|||||||
if (subUserInfo) {
|
if (subUserInfo) {
|
||||||
res.set(
|
res.set(
|
||||||
'subscription-userinfo',
|
'subscription-userinfo',
|
||||||
subUserInfo.replace(/\s*;\s*;\s*/g, ';'),
|
normalizeFlowHeader(subUserInfo),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (platform === 'JSON') {
|
if (platform === 'JSON') {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { deleteByName, findByName, updateByName } from '@/utils/database';
|
import { deleteByName, findByName, updateByName } from '@/utils/database';
|
||||||
import { getFlowHeaders } from '@/utils/flow';
|
import { getFlowHeaders, normalizeFlowHeader } from '@/utils/flow';
|
||||||
import { FILES_KEY } from '@/constants';
|
import { FILES_KEY } from '@/constants';
|
||||||
import { failed, success } from '@/restful/response';
|
import { failed, success } from '@/restful/response';
|
||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
@@ -148,7 +148,7 @@ async function getFile(req, res) {
|
|||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
res.set(
|
res.set(
|
||||||
'subscription-userinfo',
|
'subscription-userinfo',
|
||||||
flowInfo.replace(/\s*;\s*;\s*/g, ';'),
|
normalizeFlowHeader(flowInfo),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,18 @@ function getWholeFile(req, res) {
|
|||||||
res.set('content-type', 'application/json')
|
res.set('content-type', 'application/json')
|
||||||
.set(
|
.set(
|
||||||
'content-disposition',
|
'content-disposition',
|
||||||
`attachment; filename="${encodeURIComponent(name)}.json"`,
|
`attachment; filename="${encodeURIComponent(
|
||||||
|
`sub-store_file_${name}_${new Date()
|
||||||
|
.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
})
|
||||||
|
.replace(/\D/g, '')}.json`,
|
||||||
|
)}"`,
|
||||||
)
|
)
|
||||||
.send(JSON.stringify(file));
|
.send(JSON.stringify(file));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import express from '@/vendor/express';
|
|||||||
import $ from '@/core/app';
|
import $ from '@/core/app';
|
||||||
import migrate from '@/utils/migration';
|
import migrate from '@/utils/migration';
|
||||||
import download from '@/utils/download';
|
import download from '@/utils/download';
|
||||||
import { syncArtifacts } from '@/restful/sync';
|
import { syncArtifacts, produceArtifact } from '@/restful/sync';
|
||||||
import { gistBackupAction } from '@/restful/miscs';
|
import { gistBackupAction } from '@/restful/miscs';
|
||||||
import { TOKENS_KEY } from '@/constants';
|
import { TOKENS_KEY } from '@/constants';
|
||||||
|
|
||||||
@@ -75,6 +75,39 @@ export default function serve() {
|
|||||||
// 'Asia/Shanghai' // timeZone
|
// 'Asia/Shanghai' // timeZone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// 格式: 0 */2 * * *,sub,a;0 */3 * * *,col,b
|
||||||
|
// 每 2 小时处理一次单条订阅 a, 每 3 小时处理一次组合订阅 b
|
||||||
|
const produce_cron = eval('process.env.SUB_STORE_PRODUCE_CRON');
|
||||||
|
if (produce_cron) {
|
||||||
|
$.info(`[PRODUCE CRON] ${produce_cron} enabled`);
|
||||||
|
const { CronJob } = eval(`require("cron")`);
|
||||||
|
produce_cron.split(/\s*;\s*/).map((item) => {
|
||||||
|
const [cron, type, name] = item.split(/\s*,\s*/);
|
||||||
|
new CronJob(
|
||||||
|
cron.trim(),
|
||||||
|
async function () {
|
||||||
|
try {
|
||||||
|
$.info(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} started`,
|
||||||
|
);
|
||||||
|
await produceArtifact({ type, name });
|
||||||
|
$.info(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} finished`,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
$.error(
|
||||||
|
`[PRODUCE CRON] ${type} ${name} ${cron} error: ${
|
||||||
|
e.message ?? e
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, // onTick
|
||||||
|
null, // onComplete
|
||||||
|
true, // start
|
||||||
|
// 'Asia/Shanghai' // timeZone
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
const backend_download_cron = eval(
|
const backend_download_cron = eval(
|
||||||
'process.env.SUB_STORE_BACKEND_DOWNLOAD_CRON',
|
'process.env.SUB_STORE_BACKEND_DOWNLOAD_CRON',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,7 +27,18 @@ export default function register($app) {
|
|||||||
res.set('content-type', 'application/json')
|
res.set('content-type', 'application/json')
|
||||||
.set(
|
.set(
|
||||||
'content-disposition',
|
'content-disposition',
|
||||||
'attachment; filename="sub-store.json"',
|
`attachment; filename="${encodeURIComponent(
|
||||||
|
`sub-store_data_${new Date()
|
||||||
|
.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
})
|
||||||
|
.replace(/\D/g, '')}.json`,
|
||||||
|
)}"`,
|
||||||
)
|
)
|
||||||
.send(
|
.send(
|
||||||
$.env.isNode
|
$.env.isNode
|
||||||
@@ -98,6 +109,21 @@ async function gistBackupAction(action) {
|
|||||||
const updated = settings.syncTime;
|
const updated = settings.syncTime;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'upload':
|
case 'upload':
|
||||||
|
try {
|
||||||
|
content = $.read('#sub-store');
|
||||||
|
if ($.env.isNode) content = JSON.stringify($.cache, null, ` `);
|
||||||
|
$.info(`下载备份, 与本地内容对比...`);
|
||||||
|
const onlineContent = await gist.download(
|
||||||
|
GIST_BACKUP_FILE_NAME,
|
||||||
|
);
|
||||||
|
if (onlineContent === content) {
|
||||||
|
$.info(`内容一致, 无需上传备份`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
$.error(`${error.message ?? error}`);
|
||||||
|
}
|
||||||
|
|
||||||
// update syncTime
|
// update syncTime
|
||||||
settings.syncTime = new Date().getTime();
|
settings.syncTime = new Date().getTime();
|
||||||
$.write(settings, SETTINGS_KEY);
|
$.write(settings, SETTINGS_KEY);
|
||||||
|
|||||||
@@ -15,46 +15,48 @@ export default function register($app) {
|
|||||||
async function previewFile(req, res) {
|
async function previewFile(req, res) {
|
||||||
try {
|
try {
|
||||||
const file = req.body;
|
const file = req.body;
|
||||||
let content;
|
let content = '';
|
||||||
if (
|
if (file.type !== 'mihomoProfile') {
|
||||||
file.source === 'local' &&
|
|
||||||
!['localFirst', 'remoteFirst'].includes(file.mergeSources)
|
|
||||||
) {
|
|
||||||
content = file.content;
|
|
||||||
} else {
|
|
||||||
const errors = {};
|
|
||||||
content = await Promise.all(
|
|
||||||
file.url
|
|
||||||
.split(/[\r\n]+/)
|
|
||||||
.map((i) => i.trim())
|
|
||||||
.filter((i) => i.length)
|
|
||||||
.map(async (url) => {
|
|
||||||
try {
|
|
||||||
return await download(url, file.ua);
|
|
||||||
} catch (err) {
|
|
||||||
errors[url] = err;
|
|
||||||
$.error(
|
|
||||||
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
|
||||||
);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!file.ignoreFailedRemoteFile &&
|
file.source === 'local' &&
|
||||||
Object.keys(errors).length > 0
|
!['localFirst', 'remoteFirst'].includes(file.mergeSources)
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
content = file.content;
|
||||||
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join(
|
} else {
|
||||||
', ',
|
const errors = {};
|
||||||
)} 发生错误, 请查看日志`,
|
content = await Promise.all(
|
||||||
|
file.url
|
||||||
|
.split(/[\r\n]+/)
|
||||||
|
.map((i) => i.trim())
|
||||||
|
.filter((i) => i.length)
|
||||||
|
.map(async (url) => {
|
||||||
|
try {
|
||||||
|
return await download(url, file.ua);
|
||||||
|
} catch (err) {
|
||||||
|
errors[url] = err;
|
||||||
|
$.error(
|
||||||
|
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
if (file.mergeSources === 'localFirst') {
|
if (
|
||||||
content.unshift(file.content);
|
!file.ignoreFailedRemoteFile &&
|
||||||
} else if (file.mergeSources === 'remoteFirst') {
|
Object.keys(errors).length > 0
|
||||||
content.push(file.content);
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`文件 ${file.name} 的远程文件 ${Object.keys(
|
||||||
|
errors,
|
||||||
|
).join(', ')} 发生错误, 请查看日志`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (file.mergeSources === 'localFirst') {
|
||||||
|
content.unshift(file.content);
|
||||||
|
} else if (file.mergeSources === 'remoteFirst') {
|
||||||
|
content.push(file.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// parse proxies
|
// parse proxies
|
||||||
|
|||||||
@@ -264,7 +264,18 @@ function getSubscription(req, res) {
|
|||||||
res.set('content-type', 'application/json')
|
res.set('content-type', 'application/json')
|
||||||
.set(
|
.set(
|
||||||
'content-disposition',
|
'content-disposition',
|
||||||
`attachment; filename="${encodeURIComponent(name)}.json"`,
|
`attachment; filename="${encodeURIComponent(
|
||||||
|
`sub-store_subscription_${name}_${new Date()
|
||||||
|
.toLocaleString('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric',
|
||||||
|
})
|
||||||
|
.replace(/\D/g, '')}.json`,
|
||||||
|
)}"`,
|
||||||
)
|
)
|
||||||
.send(JSON.stringify(sub));
|
.send(JSON.stringify(sub));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ async function produceArtifact({
|
|||||||
}) {
|
}) {
|
||||||
platform = platform || 'JSON';
|
platform = platform || 'JSON';
|
||||||
|
|
||||||
if (type === 'subscription') {
|
if (['subscription', 'sub'].includes(type)) {
|
||||||
let sub;
|
let sub;
|
||||||
if (name) {
|
if (name) {
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
@@ -190,7 +190,7 @@ async function produceArtifact({
|
|||||||
}
|
}
|
||||||
// produce
|
// produce
|
||||||
return ProxyUtils.produce(proxies, platform, produceType, produceOpts);
|
return ProxyUtils.produce(proxies, platform, produceType, produceOpts);
|
||||||
} else if (type === 'collection') {
|
} else if (['collection', 'col'].includes(type)) {
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
const allCols = $.read(COLLECTIONS_KEY);
|
const allCols = $.read(COLLECTIONS_KEY);
|
||||||
const collection = findByName(allCols, name);
|
const collection = findByName(allCols, name);
|
||||||
@@ -410,105 +410,117 @@ async function produceArtifact({
|
|||||||
const allFiles = $.read(FILES_KEY);
|
const allFiles = $.read(FILES_KEY);
|
||||||
const file = findByName(allFiles, name);
|
const file = findByName(allFiles, name);
|
||||||
if (!file) throw new Error(`找不到文件 ${name}`);
|
if (!file) throw new Error(`找不到文件 ${name}`);
|
||||||
let raw;
|
let raw = '';
|
||||||
if (content && !['localFirst', 'remoteFirst'].includes(mergeSources)) {
|
console.log(file);
|
||||||
raw = content;
|
if (file.type !== 'mihomoProfile') {
|
||||||
} else if (url) {
|
|
||||||
const errors = {};
|
|
||||||
raw = await Promise.all(
|
|
||||||
url
|
|
||||||
.split(/[\r\n]+/)
|
|
||||||
.map((i) => i.trim())
|
|
||||||
.filter((i) => i.length)
|
|
||||||
.map(async (url) => {
|
|
||||||
try {
|
|
||||||
return await download(
|
|
||||||
url,
|
|
||||||
ua || file.ua,
|
|
||||||
undefined,
|
|
||||||
file.proxy || proxy,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
noCache,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
errors[url] = err;
|
|
||||||
$.error(
|
|
||||||
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
|
||||||
);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile;
|
|
||||||
if (
|
if (
|
||||||
ignoreFailedRemoteFile != null &&
|
content &&
|
||||||
ignoreFailedRemoteFile !== ''
|
!['localFirst', 'remoteFirst'].includes(mergeSources)
|
||||||
) {
|
) {
|
||||||
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile;
|
raw = content;
|
||||||
}
|
} else if (url) {
|
||||||
if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) {
|
const errors = {};
|
||||||
throw new Error(
|
raw = await Promise.all(
|
||||||
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join(
|
url
|
||||||
', ',
|
.split(/[\r\n]+/)
|
||||||
)} 发生错误, 请查看日志`,
|
.map((i) => i.trim())
|
||||||
|
.filter((i) => i.length)
|
||||||
|
.map(async (url) => {
|
||||||
|
try {
|
||||||
|
return await download(
|
||||||
|
url,
|
||||||
|
ua || file.ua,
|
||||||
|
undefined,
|
||||||
|
file.proxy || proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
noCache,
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
errors[url] = err;
|
||||||
|
$.error(
|
||||||
|
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile;
|
||||||
if (mergeSources === 'localFirst') {
|
if (
|
||||||
raw.unshift(content);
|
ignoreFailedRemoteFile != null &&
|
||||||
} else if (mergeSources === 'remoteFirst') {
|
ignoreFailedRemoteFile !== ''
|
||||||
raw.push(content);
|
) {
|
||||||
}
|
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile;
|
||||||
} else if (
|
}
|
||||||
file.source === 'local' &&
|
if (
|
||||||
!['localFirst', 'remoteFirst'].includes(file.mergeSources)
|
!fileIgnoreFailedRemoteFile &&
|
||||||
) {
|
Object.keys(errors).length > 0
|
||||||
raw = file.content;
|
) {
|
||||||
} else {
|
throw new Error(
|
||||||
const errors = {};
|
`文件 ${file.name} 的远程文件 ${Object.keys(
|
||||||
raw = await Promise.all(
|
errors,
|
||||||
file.url
|
).join(', ')} 发生错误, 请查看日志`,
|
||||||
.split(/[\r\n]+/)
|
);
|
||||||
.map((i) => i.trim())
|
}
|
||||||
.filter((i) => i.length)
|
if (mergeSources === 'localFirst') {
|
||||||
.map(async (url) => {
|
raw.unshift(content);
|
||||||
try {
|
} else if (mergeSources === 'remoteFirst') {
|
||||||
return await download(
|
raw.push(content);
|
||||||
url,
|
}
|
||||||
ua || file.ua,
|
} else if (
|
||||||
undefined,
|
file.source === 'local' &&
|
||||||
file.proxy || proxy,
|
!['localFirst', 'remoteFirst'].includes(file.mergeSources)
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
noCache,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
errors[url] = err;
|
|
||||||
$.error(
|
|
||||||
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
|
||||||
);
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile;
|
|
||||||
if (
|
|
||||||
ignoreFailedRemoteFile != null &&
|
|
||||||
ignoreFailedRemoteFile !== ''
|
|
||||||
) {
|
) {
|
||||||
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile;
|
raw = file.content;
|
||||||
}
|
} else {
|
||||||
if (!fileIgnoreFailedRemoteFile && Object.keys(errors).length > 0) {
|
const errors = {};
|
||||||
throw new Error(
|
raw = await Promise.all(
|
||||||
`文件 ${file.name} 的远程文件 ${Object.keys(errors).join(
|
file.url
|
||||||
', ',
|
.split(/[\r\n]+/)
|
||||||
)} 发生错误, 请查看日志`,
|
.map((i) => i.trim())
|
||||||
|
.filter((i) => i.length)
|
||||||
|
.map(async (url) => {
|
||||||
|
try {
|
||||||
|
return await download(
|
||||||
|
url,
|
||||||
|
ua || file.ua,
|
||||||
|
undefined,
|
||||||
|
file.proxy || proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
noCache,
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
errors[url] = err;
|
||||||
|
$.error(
|
||||||
|
`文件 ${file.name} 的远程文件 ${url} 发生错误: ${err}`,
|
||||||
|
);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
let fileIgnoreFailedRemoteFile = file.ignoreFailedRemoteFile;
|
||||||
if (file.mergeSources === 'localFirst') {
|
if (
|
||||||
raw.unshift(file.content);
|
ignoreFailedRemoteFile != null &&
|
||||||
} else if (file.mergeSources === 'remoteFirst') {
|
ignoreFailedRemoteFile !== ''
|
||||||
raw.push(file.content);
|
) {
|
||||||
|
fileIgnoreFailedRemoteFile = ignoreFailedRemoteFile;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!fileIgnoreFailedRemoteFile &&
|
||||||
|
Object.keys(errors).length > 0
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`文件 ${file.name} 的远程文件 ${Object.keys(
|
||||||
|
errors,
|
||||||
|
).join(', ')} 发生错误, 请查看日志`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (file.mergeSources === 'localFirst') {
|
||||||
|
raw.unshift(file.content);
|
||||||
|
} else if (file.mergeSources === 'remoteFirst') {
|
||||||
|
raw.push(file.content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const files = (Array.isArray(raw) ? raw : [raw]).flat();
|
const files = (Array.isArray(raw) ? raw : [raw]).flat();
|
||||||
@@ -540,6 +552,7 @@ async function syncArtifacts() {
|
|||||||
const files = {};
|
const files = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const valid = [];
|
||||||
const invalid = [];
|
const invalid = [];
|
||||||
const allSubs = $.read(SUBS_KEY);
|
const allSubs = $.read(SUBS_KEY);
|
||||||
const allCols = $.read(COLLECTIONS_KEY);
|
const allCols = $.read(COLLECTIONS_KEY);
|
||||||
@@ -614,19 +627,26 @@ async function syncArtifacts() {
|
|||||||
files[encodeURIComponent(artifact.name)] = {
|
files[encodeURIComponent(artifact.name)] = {
|
||||||
content: output,
|
content: output,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
valid.push(artifact.name);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(
|
$.error(
|
||||||
`同步配置 ${artifact.name} 发生错误: ${e.message ?? e}`,
|
`生成同步配置 ${artifact.name} 发生错误: ${
|
||||||
|
e.message ?? e
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
invalid.push(artifact.name);
|
invalid.push(artifact.name);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (invalid.length > 0) {
|
$.info(`${valid.length} 个同步配置生成成功: ${valid.join(', ')}`);
|
||||||
|
$.info(`${invalid.length} 个同步配置生成失败: ${invalid.join(', ')}`);
|
||||||
|
|
||||||
|
if (valid.length === 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`同步配置 ${invalid.join(', ')} 发生错误 详情请查看日志`,
|
`同步配置 ${invalid.join(', ')} 生成失败 详情请查看日志`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,7 +663,11 @@ async function syncArtifacts() {
|
|||||||
$.info(JSON.stringify(body, null, 2));
|
$.info(JSON.stringify(body, null, 2));
|
||||||
|
|
||||||
for (const artifact of allArtifacts) {
|
for (const artifact of allArtifacts) {
|
||||||
if (artifact.sync) {
|
if (
|
||||||
|
artifact.sync &&
|
||||||
|
artifact.source &&
|
||||||
|
valid.includes(artifact.name)
|
||||||
|
) {
|
||||||
artifact.updated = new Date().getTime();
|
artifact.updated = new Date().getTime();
|
||||||
// extract real url from gist
|
// extract real url from gist
|
||||||
let files = body.files;
|
let files = body.files;
|
||||||
@@ -671,9 +695,17 @@ async function syncArtifacts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$.write(allArtifacts, ARTIFACTS_KEY);
|
$.write(allArtifacts, ARTIFACTS_KEY);
|
||||||
$.info('全部订阅同步成功!');
|
$.info('上传配置成功');
|
||||||
|
|
||||||
|
if (invalid.length > 0) {
|
||||||
|
throw new Error(
|
||||||
|
`同步配置成功 ${valid.length} 个, 失败 ${invalid.length} 个, 详情请查看日志`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$.info(`同步配置成功 ${valid.length} 个`);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(`同步订阅失败,原因:${e.message ?? e}`);
|
$.error(`同步配置失败,原因:${e.message ?? e}`);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -683,7 +715,7 @@ async function syncAllArtifacts(_, res) {
|
|||||||
await syncArtifacts();
|
await syncArtifacts();
|
||||||
success(res);
|
success(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(`同步订阅失败,原因:${e.message ?? e}`);
|
$.error(`同步配置失败,原因:${e.message ?? e}`);
|
||||||
failed(
|
failed(
|
||||||
res,
|
res,
|
||||||
new InternalServerError(
|
new InternalServerError(
|
||||||
|
|||||||
@@ -313,3 +313,41 @@ export function getRmainingDays(opt = {}) {
|
|||||||
$.error(`getRmainingDays failed: ${e.message ?? e}`);
|
$.error(`getRmainingDays failed: ${e.message ?? e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function normalizeFlowHeader(flowHeaders) {
|
||||||
|
try {
|
||||||
|
// 使用 Map 保持顺序并处理重复键
|
||||||
|
const kvMap = new Map();
|
||||||
|
|
||||||
|
flowHeaders
|
||||||
|
.split(';')
|
||||||
|
.map((p) => p.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.forEach((pair) => {
|
||||||
|
const eqIndex = pair.indexOf('=');
|
||||||
|
if (eqIndex === -1) return;
|
||||||
|
|
||||||
|
const key = pair.slice(0, eqIndex).trim();
|
||||||
|
const encodedValue = pair.slice(eqIndex + 1).trim();
|
||||||
|
|
||||||
|
// 只保留第一个出现的 key
|
||||||
|
if (!kvMap.has(key)) {
|
||||||
|
try {
|
||||||
|
// 解码 URI 组件并保留原始值作为 fallback
|
||||||
|
const decodedValue = decodeURIComponent(encodedValue);
|
||||||
|
kvMap.set(key, decodedValue);
|
||||||
|
} catch (e) {
|
||||||
|
kvMap.set(key, encodedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 拼接标准化字符串
|
||||||
|
return Array.from(kvMap.entries())
|
||||||
|
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`) // 重新编码保持兼容性
|
||||||
|
.join('; ');
|
||||||
|
} catch (e) {
|
||||||
|
$.error(`normalizeFlowHeader failed: ${e.message ?? e}`);
|
||||||
|
return flowHeaders;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ const ISOFlags = {
|
|||||||
'🇧🇬': ['BG', 'BGR'],
|
'🇧🇬': ['BG', 'BGR'],
|
||||||
'🇧🇭': ['BH', 'BHR'],
|
'🇧🇭': ['BH', 'BHR'],
|
||||||
'🇧🇴': ['BO', 'BOL'],
|
'🇧🇴': ['BO', 'BOL'],
|
||||||
|
'🇧🇳': ['BN', 'BRN'],
|
||||||
'🇧🇷': ['BR', 'BRA'],
|
'🇧🇷': ['BR', 'BRA'],
|
||||||
|
'🇧🇹': ['BT', 'BTN'],
|
||||||
'🇧🇾': ['BY', 'BLR'],
|
'🇧🇾': ['BY', 'BLR'],
|
||||||
'🇨🇦': ['CA', 'CAN'],
|
'🇨🇦': ['CA', 'CAN'],
|
||||||
'🇨🇭': ['CH', 'CHE'],
|
'🇨🇭': ['CH', 'CHE'],
|
||||||
@@ -40,6 +42,7 @@ const ISOFlags = {
|
|||||||
'🇬🇪': ['GE', 'GEO'],
|
'🇬🇪': ['GE', 'GEO'],
|
||||||
'🇬🇷': ['GR', 'GRC'],
|
'🇬🇷': ['GR', 'GRC'],
|
||||||
'🇬🇹': ['GT', 'GTM'],
|
'🇬🇹': ['GT', 'GTM'],
|
||||||
|
'🇬🇺': ['GU', 'GUM'],
|
||||||
'🇭🇰': ['HK', 'HKG', 'HKT', 'HKBN', 'HGC', 'WTT', 'CMI'],
|
'🇭🇰': ['HK', 'HKG', 'HKT', 'HKBN', 'HGC', 'WTT', 'CMI'],
|
||||||
'🇭🇷': ['HR', 'HRV'],
|
'🇭🇷': ['HR', 'HRV'],
|
||||||
'🇭🇺': ['HU', 'HUN'],
|
'🇭🇺': ['HU', 'HUN'],
|
||||||
@@ -59,12 +62,15 @@ const ISOFlags = {
|
|||||||
'🇮🇷': ['IR', 'IRN'],
|
'🇮🇷': ['IR', 'IRN'],
|
||||||
'🇮🇸': ['IS', 'ISL'],
|
'🇮🇸': ['IS', 'ISL'],
|
||||||
'🇮🇹': ['IT', 'ITA'],
|
'🇮🇹': ['IT', 'ITA'],
|
||||||
|
'🇱🇦': ['LA', 'LAO'],
|
||||||
|
'🇱🇰': ['LK', 'LKA'],
|
||||||
'🇱🇹': ['LT', 'LTU'],
|
'🇱🇹': ['LT', 'LTU'],
|
||||||
'🇱🇺': ['LU', 'LUX'],
|
'🇱🇺': ['LU', 'LUX'],
|
||||||
'🇱🇻': ['LV', 'LVA'],
|
'🇱🇻': ['LV', 'LVA'],
|
||||||
'🇲🇦': ['MA', 'MAR'],
|
'🇲🇦': ['MA', 'MAR'],
|
||||||
'🇲🇩': ['MD', 'MDA'],
|
'🇲🇩': ['MD', 'MDA'],
|
||||||
'🇳🇬': ['NG', 'NGA'],
|
'🇳🇬': ['NG', 'NGA'],
|
||||||
|
'🇲🇲': ['MM', 'MMR'],
|
||||||
'🇲🇰': ['MK', 'MKD'],
|
'🇲🇰': ['MK', 'MKD'],
|
||||||
'🇲🇳': ['MN', 'MNG'],
|
'🇲🇳': ['MN', 'MNG'],
|
||||||
'🇲🇴': ['MO', 'MAC', 'CTM'],
|
'🇲🇴': ['MO', 'MAC', 'CTM'],
|
||||||
@@ -83,6 +89,7 @@ const ISOFlags = {
|
|||||||
'🇵🇷': ['PR', 'PRI'],
|
'🇵🇷': ['PR', 'PRI'],
|
||||||
'🇵🇹': ['PT', 'PRT'],
|
'🇵🇹': ['PT', 'PRT'],
|
||||||
'🇵🇾': ['PY', 'PRY'],
|
'🇵🇾': ['PY', 'PRY'],
|
||||||
|
'🇵🇬': ['PG', 'PNG'],
|
||||||
'🇷🇴': ['RO', 'ROU'],
|
'🇷🇴': ['RO', 'ROU'],
|
||||||
'🇷🇸': ['RS', 'SRB'],
|
'🇷🇸': ['RS', 'SRB'],
|
||||||
'🇷🇪': ['RE', 'REU'],
|
'🇷🇪': ['RE', 'REU'],
|
||||||
@@ -142,8 +149,10 @@ export function getFlag(name) {
|
|||||||
'🇧🇬': ['Bulgaria', '保加利亚', '保加利亞'],
|
'🇧🇬': ['Bulgaria', '保加利亚', '保加利亞'],
|
||||||
'🇧🇭': ['Bahrain', '巴林'],
|
'🇧🇭': ['Bahrain', '巴林'],
|
||||||
'🇧🇷': ['Brazil', '巴西', '圣保罗'],
|
'🇧🇷': ['Brazil', '巴西', '圣保罗'],
|
||||||
|
'🇧🇳': ['Brunei', '文莱', '汶萊'],
|
||||||
'🇧🇾': ['Belarus', '白俄罗斯', '白俄'],
|
'🇧🇾': ['Belarus', '白俄罗斯', '白俄'],
|
||||||
'🇧🇴': ['Bolivia', '玻利维亚'],
|
'🇧🇴': ['Bolivia', '玻利维亚'],
|
||||||
|
'🇧🇹': ['Bhutan', '不丹', '不丹王国'],
|
||||||
'🇨🇦': [
|
'🇨🇦': [
|
||||||
'Canada',
|
'Canada',
|
||||||
'加拿大',
|
'加拿大',
|
||||||
@@ -194,6 +203,7 @@ export function getFlag(name) {
|
|||||||
],
|
],
|
||||||
'🇬🇪': ['Georgia', '格鲁吉亚', '格魯吉亞'],
|
'🇬🇪': ['Georgia', '格鲁吉亚', '格魯吉亞'],
|
||||||
'🇬🇷': ['Greece', '希腊', '希臘'],
|
'🇬🇷': ['Greece', '希腊', '希臘'],
|
||||||
|
'🇬🇺': ['Guam', '关岛', '關島'],
|
||||||
'🇬🇹': ['Guatemala', '危地马拉'],
|
'🇬🇹': ['Guatemala', '危地马拉'],
|
||||||
'🇭🇰': [
|
'🇭🇰': [
|
||||||
'Hongkong',
|
'Hongkong',
|
||||||
@@ -254,11 +264,14 @@ export function getFlag(name) {
|
|||||||
'🇮🇷': ['Iran', '伊朗'],
|
'🇮🇷': ['Iran', '伊朗'],
|
||||||
'🇮🇸': ['Iceland', '冰岛', '冰島'],
|
'🇮🇸': ['Iceland', '冰岛', '冰島'],
|
||||||
'🇮🇹': ['Italy', '意大利', '義大利', '米兰', 'Nachash'],
|
'🇮🇹': ['Italy', '意大利', '義大利', '米兰', 'Nachash'],
|
||||||
|
'🇱🇰': ['Sri Lanka', '斯里兰卡', '斯里蘭卡'],
|
||||||
|
'🇱🇦': ['Laos', '老挝', '老撾'],
|
||||||
'🇱🇹': ['Lithuania', '立陶宛'],
|
'🇱🇹': ['Lithuania', '立陶宛'],
|
||||||
'🇱🇺': ['Luxembourg', '卢森堡'],
|
'🇱🇺': ['Luxembourg', '卢森堡'],
|
||||||
'🇱🇻': ['Latvia', '拉脱维亚', 'Latvija'],
|
'🇱🇻': ['Latvia', '拉脱维亚', 'Latvija'],
|
||||||
'🇲🇦': ['Morocco', '摩洛哥'],
|
'🇲🇦': ['Morocco', '摩洛哥'],
|
||||||
'🇲🇩': ['Moldova', '摩尔多瓦', '摩爾多瓦'],
|
'🇲🇩': ['Moldova', '摩尔多瓦', '摩爾多瓦'],
|
||||||
|
'🇲🇲': ['Myanmar', '缅甸', '緬甸'],
|
||||||
'🇳🇬': ['Nigeria', '尼日利亚', '尼日利亞'],
|
'🇳🇬': ['Nigeria', '尼日利亚', '尼日利亞'],
|
||||||
'🇲🇰': ['Macedonia', '马其顿', '馬其頓'],
|
'🇲🇰': ['Macedonia', '马其顿', '馬其頓'],
|
||||||
'🇲🇳': ['Mongolia', '蒙古'],
|
'🇲🇳': ['Mongolia', '蒙古'],
|
||||||
@@ -284,6 +297,7 @@ export function getFlag(name) {
|
|||||||
'🇵🇱': ['Poland', '波兰', '波蘭', '华沙', 'Warsaw'],
|
'🇵🇱': ['Poland', '波兰', '波蘭', '华沙', 'Warsaw'],
|
||||||
'🇵🇷': ['Puerto Rico', '波多黎各'],
|
'🇵🇷': ['Puerto Rico', '波多黎各'],
|
||||||
'🇵🇹': ['Portugal', '葡萄牙'],
|
'🇵🇹': ['Portugal', '葡萄牙'],
|
||||||
|
'🇵🇬': ['Papua New Guinea', '巴布亚新几内亚'],
|
||||||
'🇵🇾': ['Paraguay', '巴拉圭'],
|
'🇵🇾': ['Paraguay', '巴拉圭'],
|
||||||
'🇷🇴': ['Romania', '罗马尼亚'],
|
'🇷🇴': ['Romania', '罗马尼亚'],
|
||||||
'🇷🇸': ['Serbia', '塞尔维亚'],
|
'🇷🇸': ['Serbia', '塞尔维亚'],
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export default class Gist {
|
|||||||
.get('/gists?per_page=100&page=1')
|
.get('/gists?per_page=100&page=1')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const gists = JSON.parse(response.body);
|
const gists = JSON.parse(response.body);
|
||||||
|
$.info(`获取到当前 GitHub 用户的 gist: ${gists.length} 个`);
|
||||||
for (let g of gists) {
|
for (let g of gists) {
|
||||||
if (g.description === this.key) {
|
if (g.description === this.key) {
|
||||||
return g;
|
return g;
|
||||||
|
|||||||
@@ -117,7 +117,17 @@ function numberToString(value) {
|
|||||||
: BigInt(value).toString();
|
: BigInt(value).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidUUID(uuid) {
|
||||||
|
return (
|
||||||
|
typeof uuid === 'string' &&
|
||||||
|
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(
|
||||||
|
uuid,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
isValidUUID,
|
||||||
ipAddress,
|
ipAddress,
|
||||||
isIPv4,
|
isIPv4,
|
||||||
isIPv6,
|
isIPv6,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ResourceCache {
|
|||||||
this._cleanup();
|
this._cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
_cleanup() {
|
_cleanup(prefix, expires) {
|
||||||
// clear obsolete cached resource
|
// clear obsolete cached resource
|
||||||
let clear = false;
|
let clear = false;
|
||||||
Object.entries(this.resourceCache).forEach((entry) => {
|
Object.entries(this.resourceCache).forEach((entry) => {
|
||||||
@@ -35,7 +35,11 @@ class ResourceCache {
|
|||||||
$.delete(`#${id}`);
|
$.delete(`#${id}`);
|
||||||
clear = true;
|
clear = true;
|
||||||
}
|
}
|
||||||
if (new Date().getTime() - updated.time > this.expires) {
|
if (
|
||||||
|
new Date().getTime() - updated.time >
|
||||||
|
(expires ?? this.expires) ||
|
||||||
|
(prefix && id.startsWith(prefix))
|
||||||
|
) {
|
||||||
delete this.resourceCache[id];
|
delete this.resourceCache[id];
|
||||||
clear = true;
|
clear = true;
|
||||||
}
|
}
|
||||||
@@ -52,10 +56,15 @@ class ResourceCache {
|
|||||||
$.write(JSON.stringify(this.resourceCache), SCRIPT_RESOURCE_CACHE_KEY);
|
$.write(JSON.stringify(this.resourceCache), SCRIPT_RESOURCE_CACHE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(id) {
|
get(id, expires, remove) {
|
||||||
const updated = this.resourceCache[id] && this.resourceCache[id].time;
|
const updated = this.resourceCache[id] && this.resourceCache[id].time;
|
||||||
if (updated && new Date().getTime() - updated <= this.expires) {
|
if (updated) {
|
||||||
return this.resourceCache[id].data;
|
if (new Date().getTime() - updated <= (expires ?? this.expires))
|
||||||
|
return this.resourceCache[id].data;
|
||||||
|
if (remove) {
|
||||||
|
delete this.resourceCache[id];
|
||||||
|
this._persist();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ function operator(proxies = [], targetPlatform, context) {
|
|||||||
// 16. `sing-box` 支持使用 `_network` 来设置 `network`, 例如 `tcp`, `udp`
|
// 16. `sing-box` 支持使用 `_network` 来设置 `network`, 例如 `tcp`, `udp`
|
||||||
|
|
||||||
// require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块
|
// require 为 Node.js 的 require, 在 Node.js 运行环境下 可以用来引入模块
|
||||||
|
// 例如在 Node.js 环境下, 将文件内容写入 /tmp/1.txt 文件
|
||||||
|
// const fs = eval(`require("fs")`)
|
||||||
|
// // const path = eval(`require("path")`)
|
||||||
|
// fs.writeFileSync('/tmp/1.txt', $content, "utf8");
|
||||||
|
|
||||||
// $arguments 为传入的脚本参数
|
// $arguments 为传入的脚本参数
|
||||||
|
|
||||||
@@ -48,8 +52,32 @@ function operator(proxies = [], targetPlatform, context) {
|
|||||||
// scriptResourceCache 缓存
|
// scriptResourceCache 缓存
|
||||||
// 可参考 https://t.me/zhetengsha/1003
|
// 可参考 https://t.me/zhetengsha/1003
|
||||||
// const cache = scriptResourceCache
|
// const cache = scriptResourceCache
|
||||||
// cache.set(id, data)
|
// 设置
|
||||||
// cache.get(id)
|
// cache.set('a:1', 1)
|
||||||
|
// cache.set('a:2', 2)
|
||||||
|
// 获取
|
||||||
|
// cache.get('a:1')
|
||||||
|
// 支持第二个参数: 自定义过期时间
|
||||||
|
// 支持第三个参数: 是否删除过期项
|
||||||
|
// cache.get('a:2', 1000, true)
|
||||||
|
|
||||||
|
// 清理
|
||||||
|
// cache._cleanup()
|
||||||
|
// 支持第一个参数: 匹配前缀的项也一起删除
|
||||||
|
// 支持第二个参数: 自定义过期时间
|
||||||
|
// cache._cleanup('a:', 1000)
|
||||||
|
|
||||||
|
// 关于缓存时长
|
||||||
|
|
||||||
|
// 拉取 Sub-Store 订阅时, 会自动拉取远程订阅
|
||||||
|
|
||||||
|
// 远程订阅缓存是 1 小时, 缓存的唯一 key 为 url+ user agent. 可通过前端的刷新按钮刷新缓存. 或使用参数 noCache 来禁用缓存. 例: 内部配置订阅链接时使用 http://a.com#noCache, 外部使用 sub-store 链接时使用 https://sub.store/download/1?noCache=true
|
||||||
|
|
||||||
|
// 当使用相关脚本时, 若在对应的脚本中使用参数开启缓存, 可设置持久化缓存 sub-store-csr-expiration-time 的值来自定义默认缓存时长, 默认为 172800000 (48 * 3600 * 1000, 即 48 小时)
|
||||||
|
|
||||||
|
// 🎈Loon 可在插件中设置
|
||||||
|
|
||||||
|
// 其他平台同理, 持久化缓存数据在 JSON 里
|
||||||
|
|
||||||
// ProxyUtils 为节点处理工具
|
// ProxyUtils 为节点处理工具
|
||||||
// 可参考 https://t.me/zhetengsha/1066
|
// 可参考 https://t.me/zhetengsha/1066
|
||||||
@@ -69,6 +97,7 @@ function operator(proxies = [], targetPlatform, context) {
|
|||||||
// Gist, // Gist 类
|
// Gist, // Gist 类
|
||||||
// download, // 内部的下载方法, 见 backend/src/utils/download.js
|
// download, // 内部的下载方法, 见 backend/src/utils/download.js
|
||||||
// MMDB, // Node.js 环境 可用于模拟 Surge/Loon 的 $utils.ipasn, $utils.ipaso, $utils.geoip. 具体见 https://t.me/zhetengsha/1269
|
// MMDB, // Node.js 环境 可用于模拟 Surge/Loon 的 $utils.ipasn, $utils.ipaso, $utils.geoip. 具体见 https://t.me/zhetengsha/1269
|
||||||
|
// isValidUUID, // 辅助判断是否为有效的 UUID
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// 如果只是为了快速修改或者筛选 可以参考 脚本操作支持节点快捷脚本 https://t.me/zhetengsha/970 和 脚本筛选支持节点快捷脚本 https://t.me/zhetengsha/1009
|
// 如果只是为了快速修改或者筛选 可以参考 脚本操作支持节点快捷脚本 https://t.me/zhetengsha/970 和 脚本筛选支持节点快捷脚本 https://t.me/zhetengsha/1009
|
||||||
|
|||||||
Reference in New Issue
Block a user