From ff4be7ac38aafb03dd0fcb2f6171c8912b00712d Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 29 Dec 2024 21:33:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E9=98=85=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BC=80=E5=85=B3=20`passThroughUA`=20=20=E9=80=8F=E4=BC=A0?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=9A=84=20User-Agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/download.js | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index c9ccbc6f9..8fb8ee729 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.15.8", + "version": "2.15.9", "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 4c9fc84c7..a57dd8ec5 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -16,13 +16,19 @@ export default function register($app) { $app.get('/share/col/:name', downloadCollection); $app.get('/share/sub/:name', downloadSubscription); + $app.get('/download/collection/:name/:target', async (req, res) => { + req.query.target = req.params.target; + $.info(`使用路由指定目标: ${req.params.target}`); + await downloadCollection(req, res); + }); $app.get('/download/collection/:name', downloadCollection); - $app.get('/download/:name', downloadSubscription); $app.get('/download/:name/:target', async (req, res) => { req.query.target = req.params.target; $.info(`使用路由指定目标: ${req.params.target}`); await downloadSubscription(req, res); }); + $app.get('/download/:name', downloadSubscription); + $app.get( '/download/collection/:name/api/v1/server/details', async (req, res) => { @@ -64,11 +70,9 @@ async function downloadSubscription(req, res) { const platform = req.query.target || getPlatformFromHeaders(req.headers) || 'JSON'; - + const reqUA = req.headers['user-agent'] || req.headers['User-Agent']; $.info( - `正在下载订阅:${name}\n请求 User-Agent: ${ - req.headers['user-agent'] || req.headers['User-Agent'] - }\n请求 target: ${req.query.target}\n实际输出: ${platform}`, + `正在下载订阅:${name}\n请求 User-Agent: ${reqUA}\n请求 target: ${req.query.target}\n实际输出: ${platform}`, ); let { url, @@ -150,6 +154,13 @@ async function downloadSubscription(req, res) { const sub = findByName(allSubs, name); if (sub) { try { + const passThroughUA = sub.passThroughUA; + if (passThroughUA) { + $.info( + `订阅开启了透传 User-Agent, 使用请求的 User-Agent: ${reqUA}`, + ); + ua = reqUA; + } let output = await produceArtifact({ type: 'subscription', name,