From d636e1b94ca7824dbe11afd0623f203b6a886742 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 8 Dec 2023 18:16:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=97=B6=E5=AD=90=E8=AE=A2=E9=98=85=E5=87=BA=E9=94=99=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../proxy-utils/producers/shadowrocket.js | 3 +- backend/src/restful/preview.js | 105 +++++++++--------- 3 files changed, 58 insertions(+), 52 deletions(-) diff --git a/backend/package.json b/backend/package.json index b425b74..d8a385f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.115", + "version": "2.14.116", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/producers/shadowrocket.js b/backend/src/core/proxy-utils/producers/shadowrocket.js index 61f5a71..75d0df0 100644 --- a/backend/src/core/proxy-utils/producers/shadowrocket.js +++ b/backend/src/core/proxy-utils/producers/shadowrocket.js @@ -84,7 +84,8 @@ export default function ShadowRocket_Producer() { } else if (proxy.type === 'hysteria2') { if ( proxy['obfs-password'] && - proxy.obfs == 'salamander') { + proxy.obfs == 'salamander' + ) { proxy.obfs = proxy['obfs-password']; delete proxy['obfs-password']; } diff --git a/backend/src/restful/preview.js b/backend/src/restful/preview.js index 68896ec..980b0aa 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -87,64 +87,69 @@ async function compareCollection(req, res) { const collection = req.body; const subnames = collection.subscriptions; const results = {}; - + let hasError; await Promise.all( subnames.map(async (name) => { - const sub = findByName(allSubs, name); - try { - let raw; - if ( - sub.source === 'local' && - !['localFirst', 'remoteFirst'].includes( - sub.mergeSources, - ) - ) { - raw = sub.content; - } else { - raw = await Promise.all( - sub.url - .split(/[\r\n]+/) - .map((i) => i.trim()) - .filter((i) => i.length) - .map((url) => download(url, sub.ua)), + if (!hasError) { + const sub = findByName(allSubs, name); + try { + let raw; + if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes( + sub.mergeSources, + ) + ) { + raw = sub.content; + } else { + raw = await Promise.all( + sub.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, sub.ua)), + ); + if (sub.mergeSources === 'localFirst') { + raw.unshift(sub.content); + } else if (sub.mergeSources === 'remoteFirst') { + raw.push(sub.content); + } + } + // parse proxies + let currentProxies = (Array.isArray(raw) ? raw : [raw]) + .map((i) => ProxyUtils.parse(i)) + .flat(); + + currentProxies.forEach((proxy) => { + proxy.subName = sub.name; + proxy.collectionName = collection.name; + }); + + // apply processors + currentProxies = await ProxyUtils.process( + currentProxies, + sub.process || [], + 'JSON', + { [sub.name]: sub, _collection: collection }, ); - if (sub.mergeSources === 'localFirst') { - raw.unshift(sub.content); - } else if (sub.mergeSources === 'remoteFirst') { - raw.push(sub.content); + results[name] = currentProxies; + } catch (err) { + if (!hasError) { + hasError = true; + failed( + res, + new InternalServerError( + 'PROCESS_FAILED', + `处理子订阅 ${name} 失败`, + `Reason: ${err}`, + ), + ); } } - // parse proxies - let currentProxies = (Array.isArray(raw) ? raw : [raw]) - .map((i) => ProxyUtils.parse(i)) - .flat(); - - currentProxies.forEach((proxy) => { - proxy.subName = sub.name; - proxy.collectionName = collection.name; - }); - - // apply processors - currentProxies = await ProxyUtils.process( - currentProxies, - sub.process || [], - 'JSON', - { [sub.name]: sub, _collection: collection }, - ); - results[name] = currentProxies; - } catch (err) { - failed( - res, - new InternalServerError( - 'PROCESS_FAILED', - `处理子订阅 ${name} 失败`, - `Reason: ${err}`, - ), - ); } }), ); - + if (hasError) return; // merge proxies with the original order const original = Array.prototype.concat.apply( [],