From 5e14d05c306b30f52eca2442a5f4a47551ca638d Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 26 Aug 2023 20:27:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E5=90=88=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E5=B0=86=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=94=99=E8=AF=AF=E7=9A=84=E5=AD=90=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E5=90=8D=E7=A7=B0;=20=E8=8E=B7=E5=8F=96=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E5=A4=B1=E8=B4=A5=E6=97=B6,=20=E4=B8=8D=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=E8=8A=82=E7=82=B9=E8=AE=A2=E9=98=85;=20=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E4=B8=8A=E6=B8=B8=E6=97=A0=E6=9C=89=E6=95=88=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=97=B6=E5=B0=86=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/download.js | 38 +++++++++++++++++++++++---------- backend/src/restful/miscs.js | 2 +- backend/src/restful/sync.js | 17 +++++++++++++-- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/backend/package.json b/backend/package.json index a7aee34..28097dc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.29", + "version": "2.14.30", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index a369084..0bdc2e3 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -32,10 +32,18 @@ async function downloadSubscription(req, res) { }); if (sub.source !== 'local') { - // forward flow headers - const flowInfo = await getFlowHeaders(sub.url); - if (flowInfo) { - res.set('subscription-userinfo', flowInfo); + try { + // forward flow headers + const flowInfo = await getFlowHeaders(sub.url); + if (flowInfo) { + res.set('subscription-userinfo', flowInfo); + } + } catch (err) { + $.error( + `订阅 ${name} 获取流量信息时发生错误: ${JSON.stringify( + err, + )}`, + ); } } @@ -50,15 +58,15 @@ async function downloadSubscription(req, res) { $.notify( `🌍 Sub-Store 下载订阅失败`, `❌ 无法下载订阅:${name}!`, - `🤔 原因:${JSON.stringify(err)}`, + `🤔 原因:${err.message ?? err}`, ); - $.error(JSON.stringify(err)); + $.error(err.message ?? err); failed( res, new InternalServerError( 'INTERNAL_SERVER_ERROR', `Failed to download subscription: ${name}`, - `Reason: ${JSON.stringify(err)}`, + `Reason: ${err.message ?? err}`, ), ); } @@ -101,9 +109,17 @@ async function downloadCollection(req, res) { if (subnames.length > 0) { const sub = findByName(allSubs, subnames[0]); if (sub.source !== 'local') { - const flowInfo = await getFlowHeaders(sub.url); - if (flowInfo) { - res.set('subscription-userinfo', flowInfo); + try { + const flowInfo = await getFlowHeaders(sub.url); + if (flowInfo) { + res.set('subscription-userinfo', flowInfo); + } + } catch (err) { + $.error( + `组合订阅 ${name} 中的子订阅 ${ + sub.name + } 获取流量信息时发生错误: ${err.message ?? err}`, + ); } } } @@ -126,7 +142,7 @@ async function downloadCollection(req, res) { new InternalServerError( 'INTERNAL_SERVER_ERROR', `Failed to download collection: ${name}`, - `Reason: ${JSON.stringify(err)}`, + `Reason: ${err.message ?? err}`, ), ); } diff --git a/backend/src/restful/miscs.js b/backend/src/restful/miscs.js index b03e146..e4f6af1 100644 --- a/backend/src/restful/miscs.js +++ b/backend/src/restful/miscs.js @@ -136,7 +136,7 @@ async function gistBackup(req, res) { new InternalServerError( 'BACKUP_FAILED', `Failed to ${action} data to gist!`, - `Reason: ${JSON.stringify(err)}`, + `Reason: ${err.message ?? err}`, ), ); } diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index fc88bc1..54b5140 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -42,6 +42,9 @@ async function produceArtifact({ type, name, platform }) { sub.process || [], platform, ); + if (proxies.length === 0) { + throw new Error(`订阅 ${name} 中不含有效节点`); + } // check duplicate const exist = {}; for (const proxy of proxies) { @@ -67,6 +70,7 @@ async function produceArtifact({ type, name, platform }) { const collection = findByName(allCols, name); const subnames = collection.subscriptions; const results = {}; + const errors = {}; let processed = 0; await Promise.all( @@ -97,6 +101,7 @@ async function produceArtifact({ type, name, platform }) { ); } catch (err) { processed++; + errors[name] = err; $.error( `❌ 处理组合订阅中的子订阅: ${ sub.name @@ -108,10 +113,18 @@ async function produceArtifact({ type, name, platform }) { }), ); + if (Object.keys(errors).length > 0) { + throw new Error( + `组合订阅 ${name} 中的子订阅 ${Object.keys(errors).join( + ', ', + )} 发生错误, 请查看日志`, + ); + } + // merge proxies with the original order let proxies = Array.prototype.concat.apply( [], - subnames.map((name) => results[name]), + subnames.map((name) => results[name] || []), ); // apply own processors @@ -121,7 +134,7 @@ async function produceArtifact({ type, name, platform }) { platform, ); if (proxies.length === 0) { - throw new Error(`组合订阅中不含有效节点!`); + throw new Error(`组合订阅 ${name} 中不含有效节点`); } // check duplicate const exist = {};