From 3054d5cd5d38807883c7f7a86619e032f4849f70 Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 29 Nov 2023 02:24:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=9C=E7=A8=8B=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8D=A2=E8=A1=8C=E7=AC=A6=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E7=9A=84=E5=A4=9A=E4=B8=AA=E8=AE=A2=E9=98=85=E9=93=BE=E6=8E=A5?= =?UTF-8?q?(=E5=89=8D=E7=AB=AF=E7=89=88=E6=9C=AC=20>=20`2.14.13`=20?= =?UTF-8?q?=E5=8F=AF=E8=BE=93=E5=85=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/preview.js | 24 ++++++++++++++++++++---- backend/src/restful/sync.js | 33 ++++++++++++++++++++++++++++----- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/backend/package.json b/backend/package.json index 209d70b..0c9bffa 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.103", + "version": "2.14.104", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/preview.js b/backend/src/restful/preview.js index d8743dc..97d1b50 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -20,7 +20,13 @@ async function compareSub(req, res) { content = sub.content; } else { try { - content = await download(sub.url, sub.ua); + content = await Promise.all( + sub.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, sub.ua)), + ); } catch (err) { failed( res, @@ -34,7 +40,9 @@ async function compareSub(req, res) { } } // parse proxies - const original = ProxyUtils.parse(content); + const original = (Array.isArray(content) ? content : [content]) + .map((i) => ProxyUtils.parse(i)) + .flat(); // add id original.forEach((proxy, i) => { @@ -80,10 +88,18 @@ async function compareCollection(req, res) { if (sub.source === 'local') { raw = sub.content; } else { - raw = await download(sub.url, sub.ua); + raw = await Promise.all( + sub.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, sub.ua)), + ); } // parse proxies - let currentProxies = ProxyUtils.parse(raw); + let currentProxies = (Array.isArray(raw) ? raw : [raw]) + .map((i) => ProxyUtils.parse(i)) + .flat(); currentProxies.forEach((proxy) => { proxy.subName = sub.name; diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index fbff455..d860746 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -30,16 +30,31 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { const sub = findByName(allSubs, name); let raw; if (url) { - raw = await download(url, ua); + raw = await Promise.all( + url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, ua)), + ); } else if (content) { raw = content; } else if (sub.source === 'local') { raw = sub.content; } else { - raw = await download(sub.url, sub.ua); + raw = await Promise.all( + sub.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, sub.ua)), + ); } // parse proxies - let proxies = ProxyUtils.parse(raw); + let proxies = (Array.isArray(raw) ? raw : [raw]) + .map((i) => ProxyUtils.parse(i)) + .flat(); + proxies.forEach((proxy) => { proxy.subName = sub.name; }); @@ -90,10 +105,18 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { if (sub.source === 'local') { raw = sub.content; } else { - raw = await download(sub.url, sub.ua); + raw = await await Promise.all( + sub.url + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length) + .map((url) => download(url, sub.ua)), + ); } // parse proxies - let currentProxies = ProxyUtils.parse(raw); + let currentProxies = (Array.isArray(raw) ? raw : [raw]) + .map((i) => ProxyUtils.parse(i)) + .flat(); currentProxies.forEach((proxy) => { proxy.subName = sub.name;