From 53925518b4797c13263f41d0f2b1a423a491da07 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 14 Nov 2023 21:46:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Sub-Store=20=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E5=9C=B0=E5=9D=80=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=20=E8=AE=A2=E9=98=85=E9=93=BE=E6=8E=A5/User-Agent/?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=86=85=E5=AE=B9=20=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E5=A4=8D=E7=94=A8=E6=AD=A4=E8=AE=A2=E9=98=85=E7=9A=84=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 例如: 建一个 name 为 sub 的订阅, 配置好节点操作 以后可以自由传入参数 无需在 Sub-Store 前端创建新的配置 `/download/sub?target=Surge&content=encodeURIComponent编码过的本地节点` `/download/sub?target=Surge&url=encodeURIComponent编码过的订阅链接&ua=encodeURIComponent编码过的User-Agent` --- backend/package.json | 2 +- backend/src/restful/download.js | 17 +++++++++++++++-- backend/src/restful/sync.js | 8 ++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 2399c89..0bc242d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.90", + "version": "2.14.91", "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 0bdc2e3..bf9e6d7 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -20,6 +20,16 @@ async function downloadSubscription(req, res) { req.query.target || getPlatformFromHeaders(req.headers) || 'JSON'; $.info(`正在下载订阅:${name}`); + const { url, ua, content } = req.query; + if (url) { + $.info(`指定 url: ${url}`); + } + if (ua) { + $.info(`指定 ua: ${ua}`); + } + if (content) { + $.info(`指定 content: ${content}`); + } const allSubs = $.read(SUBS_KEY); const sub = findByName(allSubs, name); @@ -29,12 +39,15 @@ async function downloadSubscription(req, res) { type: 'subscription', name, platform, + url, + ua, + content, }); - if (sub.source !== 'local') { + if (sub.source !== 'local' || url) { try { // forward flow headers - const flowInfo = await getFlowHeaders(sub.url); + const flowInfo = await getFlowHeaders(url || sub.url); if (flowInfo) { res.set('subscription-userinfo', flowInfo); } diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index 51a0932..fbff455 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -22,14 +22,18 @@ export default function register($app) { $app.get('/api/sync/artifact/:name', syncArtifact); } -async function produceArtifact({ type, name, platform }) { +async function produceArtifact({ type, name, platform, url, ua, content }) { platform = platform || 'JSON'; if (type === 'subscription') { const allSubs = $.read(SUBS_KEY); const sub = findByName(allSubs, name); let raw; - if (sub.source === 'local') { + if (url) { + raw = await download(url, ua); + } else if (content) { + raw = content; + } else if (sub.source === 'local') { raw = sub.content; } else { raw = await download(sub.url, sub.ua);