Skip to content

Commit

Permalink
fix: 找不到资源时报错; 调整脚本操作类型判断; 执行脚本失败时, 同时输出普通脚本和快捷脚本错误
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 14, 2024
1 parent 27a14bb commit 88f3198
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.157",
"version": "2.14.158",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
19 changes: 10 additions & 9 deletions backend/src/core/proxy-utils/processors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,19 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
const operator = createDynamicFunction(
'operator',
`async function operator(input = []) {
if (Array.isArray(input)) {
if (input?.$files || input?.$content) {
let { $content, $files } = input
${script}
return { $content, $files }
} else {
let proxies = input
let list = []
for await (let $server of proxies) {
${script}
list.push($server)
}
return list
} else {
let { $content, $files } = input
${script}
return { $content, $files }
}
}`,
$arguments,
);
Expand Down Expand Up @@ -689,7 +688,7 @@ async function ApplyFilter(filter, objs) {
nodeErr = '';
funcErr = `执行失败 ${funcErrMsg}`;
} else {
nodeErr = `执行节点快捷过滤脚本 失败 ${nodeErr}`;
nodeErr = `执行节点快捷过滤脚本 失败 ${nodeErrMsg}`;
}
throw new Error(`脚本过滤 ${funcErr}${nodeErr}`);
}
Expand All @@ -708,7 +707,9 @@ async function ApplyOperator(operator, objs) {
if (
funcErrMsg.includes('$server is not defined') ||
funcErrMsg.includes('$content is not defined') ||
funcErrMsg.includes('$files is not defined')
funcErrMsg.includes('$files is not defined') ||
output?.$files ||
output?.$content
) {
funcErr = '';
} else {
Expand All @@ -730,7 +731,7 @@ async function ApplyOperator(operator, objs) {
nodeErr = '';
funcErr = `执行失败 ${funcErrMsg}`;
} else {
nodeErr = `执行节点快捷脚本 失败 ${nodeErr}`;
nodeErr = `执行节点快捷脚本 失败 ${nodeErrMsg}`;
}
throw new Error(`脚本操作 ${funcErr}${nodeErr}`);
}
Expand Down
3 changes: 3 additions & 0 deletions backend/src/restful/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function produceArtifact({
if (type === 'subscription') {
const allSubs = $.read(SUBS_KEY);
const sub = findByName(allSubs, name);
if (!sub) throw new Error(`找不到订阅 ${name}`);
let raw;
if (content && !['localFirst', 'remoteFirst'].includes(mergeSources)) {
raw = content;
Expand Down Expand Up @@ -161,6 +162,7 @@ async function produceArtifact({
const allSubs = $.read(SUBS_KEY);
const allCols = $.read(COLLECTIONS_KEY);
const collection = findByName(allCols, name);
if (!collection) throw new Error(`找不到组合订阅 ${name}`);
const subnames = collection.subscriptions;
const results = {};
const errors = {};
Expand Down Expand Up @@ -307,6 +309,7 @@ async function produceArtifact({
} else if (type === 'rule') {
const allRules = $.read(RULES_KEY);
const rule = findByName(allRules, name);
if (!rule) throw new Error(`找不到规则 ${name}`);
let rules = [];
for (let i = 0; i < rule.urls.length; i++) {
const url = rule.urls[i];
Expand Down

0 comments on commit 88f3198

Please sign in to comment.