mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-22 03:49:08 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cacc106c68 | ||
![]() |
542fcc44a1 | ||
![]() |
dca3d2f79c | ||
![]() |
3e14f91347 | ||
![]() |
4aafdaaddb | ||
![]() |
e4f646af0c |
@ -42,7 +42,7 @@ Core functionalities:
|
||||
- [x] Clash.Meta (Direct, SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, Hysteria 2, TUIC, SSH, mieru, AnyTLS)
|
||||
- [x] Stash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard, Hysteria, TUIC, Juicity, SSH)
|
||||
|
||||
Deprecated:
|
||||
Deprecated(The frontend doesn't show it, but the backend still supports it, with the query parameter `target=Clash`):
|
||||
|
||||
- [x] Clash (SS, SSR, VMess, Trojan, HTTP, SOCKS5, Snell, VLESS, WireGuard)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.19.55",
|
||||
"version": "2.19.60",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -142,9 +142,9 @@ async function processFn(
|
||||
? `#${rawArgs[1]}`
|
||||
: ''
|
||||
}`;
|
||||
const downloadUrlMatch = url.match(
|
||||
/^\/api\/(file|module)\/(.+)/,
|
||||
);
|
||||
const downloadUrlMatch = url
|
||||
.split('#')[0]
|
||||
.match(/^\/api\/(file|module)\/(.+)/);
|
||||
if (downloadUrlMatch) {
|
||||
let type = '';
|
||||
try {
|
||||
@ -174,6 +174,17 @@ async function processFn(
|
||||
);
|
||||
throw new Error(`无法加载 ${type}: ${url}`);
|
||||
}
|
||||
} else if (url?.startsWith('/')) {
|
||||
try {
|
||||
const fs = eval(`require("fs")`);
|
||||
script = fs.readFileSync(url.split('#')[0], 'utf8');
|
||||
// $.info(`Script loaded: >>>\n ${script}`);
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Error when reading local script: ${item.args.content}.\n Reason: ${err}`,
|
||||
);
|
||||
throw new Error(`无法从该路径读取脚本文件: ${url}`);
|
||||
}
|
||||
} else {
|
||||
// if this is a remote script, download it
|
||||
try {
|
||||
|
@ -519,6 +519,7 @@ const vlessParser = (proxy = {}) => {
|
||||
};
|
||||
if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535)
|
||||
throw 'invalid port';
|
||||
if (proxy.xudp) parsedProxy.packet_encoding = 'xudp';
|
||||
if (proxy['fast-open']) parsedProxy.udp_fragment = true;
|
||||
if (proxy.flow === 'xtls-rprx-vision') parsedProxy.flow = proxy.flow;
|
||||
if (proxy.network === 'ws') wsParser(proxy, parsedProxy);
|
||||
|
@ -259,7 +259,7 @@ async function downloadSubscription(req, res) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$arguments.noFlow) {
|
||||
if (!$arguments.noFlow && /^https?/.test(url)) {
|
||||
// forward flow headers
|
||||
flowInfo = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
@ -506,7 +506,7 @@ async function downloadCollection(req, res) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$arguments.noFlow) {
|
||||
if (!$arguments.noFlow && /^https?:/.test(url)) {
|
||||
subUserInfoOfSub = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
$arguments.flowUserAgent,
|
||||
|
@ -150,6 +150,7 @@ async function getFile(req, res) {
|
||||
proxy,
|
||||
noCache,
|
||||
produceType,
|
||||
all: true,
|
||||
});
|
||||
|
||||
try {
|
||||
@ -184,9 +185,15 @@ async function getFile(req, res) {
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
res.set('Content-Type', 'text/plain; charset=utf-8').send(
|
||||
output ?? '',
|
||||
);
|
||||
res.set('Content-Type', 'text/plain; charset=utf-8');
|
||||
if (output?.$options?._res?.headers) {
|
||||
Object.entries(output.$options._res.headers).forEach(
|
||||
([key, value]) => {
|
||||
res.set(key, value);
|
||||
},
|
||||
);
|
||||
}
|
||||
res.send(output?.$content ?? '');
|
||||
} catch (err) {
|
||||
$.notify(
|
||||
`🌍 Sub-Store 下载文件失败`,
|
||||
|
@ -140,7 +140,7 @@ async function getFlowInfo(req, res) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($arguments.noFlow) {
|
||||
if ($arguments.noFlow || !/^https?/.test(url)) {
|
||||
failed(
|
||||
res,
|
||||
new RequestInvalidError(
|
||||
|
@ -40,6 +40,7 @@ async function produceArtifact({
|
||||
$options,
|
||||
proxy,
|
||||
noCache,
|
||||
all,
|
||||
}) {
|
||||
platform = platform || 'JSON';
|
||||
|
||||
@ -595,7 +596,7 @@ async function produceArtifact({
|
||||
)
|
||||
: { $content: filesContent, $files: files, $options };
|
||||
|
||||
return processed?.$content ?? '';
|
||||
return (all ? processed : processed?.$content) ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { SETTINGS_KEY } from '@/constants';
|
||||
import { SETTINGS_KEY, FILES_KEY, MODULES_KEY } from '@/constants';
|
||||
import { HTTP, ENV } from '@/vendor/open-api';
|
||||
import { hex_md5 } from '@/vendor/md5';
|
||||
import { getPolicyDescriptor } from '@/utils';
|
||||
@ -11,6 +11,8 @@ import {
|
||||
validCheck,
|
||||
} from '@/utils/flow';
|
||||
import $ from '@/core/app';
|
||||
import { findByName } from '@/utils/database';
|
||||
import { produceArtifact } from '@/restful/sync';
|
||||
import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors';
|
||||
const clashPreprocessor = PROXY_PREPROCESSORS.find(
|
||||
(processor) => processor.name === 'Clash Pre-processor',
|
||||
@ -130,22 +132,53 @@ export default async function download(
|
||||
}
|
||||
}
|
||||
|
||||
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
||||
// if (downloadUrlMatch) {
|
||||
// let type = downloadUrlMatch?.[1];
|
||||
// let name = downloadUrlMatch?.[2];
|
||||
// if (name == null) {
|
||||
// throw new Error(`本地 ${type} URL 无效: ${url}`);
|
||||
// }
|
||||
// name = decodeURIComponent(name);
|
||||
// const key = type === 'module' ? MODULES_KEY : FILES_KEY;
|
||||
// const item = findByName($.read(key), name);
|
||||
// if (!item) {
|
||||
// throw new Error(`找不到本地 ${type}: ${name}`);
|
||||
// }
|
||||
const downloadUrlMatch = url
|
||||
.split('#')[0]
|
||||
.match(/^\/api\/(file|module)\/(.+)/);
|
||||
if (downloadUrlMatch) {
|
||||
let type = '';
|
||||
try {
|
||||
type = downloadUrlMatch?.[1];
|
||||
let name = downloadUrlMatch?.[2];
|
||||
if (name == null) {
|
||||
throw new Error(`本地 ${type} URL 无效: ${url}`);
|
||||
}
|
||||
name = decodeURIComponent(name);
|
||||
const key = type === 'module' ? MODULES_KEY : FILES_KEY;
|
||||
const item = findByName($.read(key), name);
|
||||
if (!item) {
|
||||
throw new Error(`找不到 ${type}: ${name}`);
|
||||
}
|
||||
|
||||
// return item.content;
|
||||
// }
|
||||
if (type === 'module') {
|
||||
return item.content;
|
||||
} else {
|
||||
return await produceArtifact({
|
||||
type: 'file',
|
||||
name,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Error when loading ${type}: ${
|
||||
url.split('#')[0]
|
||||
}.\n Reason: ${err}`,
|
||||
);
|
||||
throw new Error(`无法加载 ${type}: ${url}`);
|
||||
}
|
||||
} else if (url?.startsWith('/')) {
|
||||
try {
|
||||
const fs = eval(`require("fs")`);
|
||||
return fs.readFileSync(url.split('#')[0], 'utf8');
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Error when reading local file: ${
|
||||
url.split('#')[0]
|
||||
}.\n Reason: ${err}`,
|
||||
);
|
||||
throw new Error(`无法从该路径读取文本内容: ${url}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNode && tasks.has(id)) {
|
||||
return tasks.get(id);
|
||||
|
@ -49,7 +49,7 @@ export async function getFlowHeaders(
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($arguments?.noFlow) {
|
||||
if ($arguments?.noFlow || !/^https?/.test(url)) {
|
||||
return;
|
||||
}
|
||||
const { isStash, isLoon, isShadowRocket, isQX } = ENV();
|
||||
|
@ -59,6 +59,15 @@ function operator(proxies = [], targetPlatform, context) {
|
||||
// }
|
||||
// console.log($options)
|
||||
|
||||
// 若设置 $options._res.headers
|
||||
// 则会在输出文件时设置响应头, 例如:
|
||||
|
||||
// $options._res = {
|
||||
// headers: {
|
||||
// 'X-Custom': '1'
|
||||
// }
|
||||
// }
|
||||
|
||||
// targetPlatform 为输出的目标平台
|
||||
|
||||
// lodash
|
||||
|
Loading…
x
Reference in New Issue
Block a user