From c541b830377857ecc79991bc46cf7e573480213a Mon Sep 17 00:00:00 2001 From: xream Date: Wed, 29 Nov 2023 03:42:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=8C=89=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E5=90=88=E5=B9=B6=E6=9C=AC=E5=9C=B0=E5=92=8C=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=AE=A2=E9=98=85(=E5=89=8D=E7=AB=AF=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20>=20`2.14.14`=20=E5=8F=AF=E8=BE=93=E5=85=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 2 +- backend/package.json | 2 +- backend/src/restful/download.js | 13 +++++++--- backend/src/restful/preview.js | 22 +++++++++++++++-- backend/src/restful/sync.js | 43 ++++++++++++++++++++++++++++----- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 195549e..20eeefe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,7 @@ jobs: run: | cd backend SUBSTORE_RELEASE=`node --eval="process.stdout.write(require('./package.json').version)"` - echo "::set-output name=release_tag::$SUBSTORE_RELEASE" + echo "release_tag=$SUBSTORE_RELEASE" >> $GITHUB_OUTPUT - name: Prepare release run: | cd backend diff --git a/backend/package.json b/backend/package.json index 0c9bffa..a87ca3b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.104", + "version": "2.14.106", "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 d729786..6a9e4c8 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -20,18 +20,22 @@ async function downloadSubscription(req, res) { req.query.target || getPlatformFromHeaders(req.headers) || 'JSON'; $.info(`正在下载订阅:${name}`); - let { url, ua, content } = req.query; + let { url, ua, content, mergeSources } = req.query; if (url) { url = decodeURIComponent(url); - $.info(`指定 url: ${url}`); + $.info(`指定远程订阅 URL: ${url}`); } if (ua) { ua = decodeURIComponent(ua); - $.info(`指定 ua: ${ua}`); + $.info(`指定远程订阅 User-Agent: ${ua}`); } if (content) { content = decodeURIComponent(content); - $.info(`指定 content: ${content}`); + $.info(`指定本地订阅: ${content}`); + } + if (mergeSources) { + mergeSources = decodeURIComponent(mergeSources); + $.info(`指定合并来源: ${mergeSources}`); } const allSubs = $.read(SUBS_KEY); @@ -45,6 +49,7 @@ async function downloadSubscription(req, res) { url, ua, content, + mergeSources, }); if (sub.source !== 'local' || url) { diff --git a/backend/src/restful/preview.js b/backend/src/restful/preview.js index 97d1b50..68896ec 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -16,7 +16,10 @@ async function compareSub(req, res) { const sub = req.body; const target = req.query.target || 'JSON'; let content; - if (sub.source === 'local') { + if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes(sub.mergeSources) + ) { content = sub.content; } else { try { @@ -38,6 +41,11 @@ async function compareSub(req, res) { ); return; } + if (sub.mergeSources === 'localFirst') { + content.unshift(sub.content); + } else if (sub.mergeSources === 'remoteFirst') { + content.push(sub.content); + } } // parse proxies const original = (Array.isArray(content) ? content : [content]) @@ -85,7 +93,12 @@ async function compareCollection(req, res) { const sub = findByName(allSubs, name); try { let raw; - if (sub.source === 'local') { + if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes( + sub.mergeSources, + ) + ) { raw = sub.content; } else { raw = await Promise.all( @@ -95,6 +108,11 @@ async function compareCollection(req, res) { .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]) diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index d860746..c80fe39 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -22,14 +22,24 @@ export default function register($app) { $app.get('/api/sync/artifact/:name', syncArtifact); } -async function produceArtifact({ type, name, platform, url, ua, content }) { +async function produceArtifact({ + type, + name, + platform, + url, + ua, + content, + mergeSources, +}) { platform = platform || 'JSON'; if (type === 'subscription') { const allSubs = $.read(SUBS_KEY); const sub = findByName(allSubs, name); let raw; - if (url) { + if (content && !['localFirst', 'remoteFirst'].includes(mergeSources)) { + raw = content; + } else if (url) { raw = await Promise.all( url .split(/[\r\n]+/) @@ -37,9 +47,15 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { .filter((i) => i.length) .map((url) => download(url, ua)), ); - } else if (content) { - raw = content; - } else if (sub.source === 'local') { + if (mergeSources === 'localFirst') { + raw.unshift(content); + } else if (mergeSources === 'remoteFirst') { + raw.push(content); + } + } else if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes(sub.mergeSources) + ) { raw = sub.content; } else { raw = await Promise.all( @@ -49,6 +65,11 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { .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 proxies = (Array.isArray(raw) ? raw : [raw]) @@ -102,7 +123,12 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { try { $.info(`正在处理子订阅:${sub.name}...`); let raw; - if (sub.source === 'local') { + if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes( + sub.mergeSources, + ) + ) { raw = sub.content; } else { raw = await await Promise.all( @@ -112,6 +138,11 @@ async function produceArtifact({ type, name, platform, url, ua, content }) { .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])