From 4819ae95e4f7323a997b5e31bd65d326ba195104 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 19 Apr 2024 05:57:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=93=AA=E5=90=92=E6=8E=A2=E9=92=88?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E7=9B=91=E6=8E=A7=E6=8E=A5=E5=8F=A3=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=9A=84=E8=8A=82=E7=82=B9?= =?UTF-8?q?,=20=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/download.js | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/backend/package.json b/backend/package.json index a58468a..becf5de 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.289", + "version": "2.14.290", "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 e53ff27..3b94344 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -31,7 +31,7 @@ export default function register($app) { await downloadSubscription(req, res); }); $app.get( - '/download/collection/:name/api/v1/monitor/:index', + '/download/collection/:name/api/v1/monitor/:nezhaIndex', async (req, res) => { req.query.platform = 'JSON'; req.query.produceType = 'internal'; @@ -39,7 +39,7 @@ export default function register($app) { await downloadCollection(req, res); }, ); - $app.get('/download/:name/api/v1/monitor/:index', async (req, res) => { + $app.get('/download/:name/api/v1/monitor/:nezhaIndex', async (req, res) => { req.query.platform = 'JSON'; req.query.produceType = 'internal'; req.query.resultFormat = 'nezha-monitor'; @@ -48,9 +48,9 @@ export default function register($app) { } async function downloadSubscription(req, res) { - let { name, index: nezhaIndex } = req.params; - nezhaIndex = parseInt(nezhaIndex, 10); + let { name, nezhaIndex } = req.params; name = decodeURIComponent(name); + nezhaIndex = decodeURIComponent(nezhaIndex); const platform = req.query.target || getPlatformFromHeaders(req.headers) || 'JSON'; @@ -173,6 +173,9 @@ async function downloadSubscription(req, res) { if (resultFormat === 'nezha') { output = nezhaTransform(output); } else if (resultFormat === 'nezha-monitor') { + nezhaIndex = /^\d+$/.test(nezhaIndex) + ? parseInt(nezhaIndex, 10) + : output.findIndex((i) => i.name === nezhaIndex); output = await nezhaMonitor(output[nezhaIndex], nezhaIndex); } res.set('Content-Type', 'application/json;charset=utf-8').send( @@ -211,9 +214,9 @@ async function downloadSubscription(req, res) { } async function downloadCollection(req, res) { - let { name, index: nezhaIndex } = req.params; - nezhaIndex = parseInt(nezhaIndex, 10); + let { name, nezhaIndex } = req.params; name = decodeURIComponent(name); + nezhaIndex = decodeURIComponent(nezhaIndex); const platform = req.query.target || getPlatformFromHeaders(req.headers) || 'JSON'; @@ -321,6 +324,9 @@ async function downloadCollection(req, res) { if (resultFormat === 'nezha') { output = nezhaTransform(output); } else if (resultFormat === 'nezha-monitor') { + nezhaIndex = /^\d+$/.test(nezhaIndex) + ? parseInt(nezhaIndex, 10) + : output.findIndex((i) => i.name === nezhaIndex); output = await nezhaMonitor(output[nezhaIndex], nezhaIndex); } res.set('Content-Type', 'application/json;charset=utf-8').send( @@ -372,6 +378,7 @@ async function nezhaMonitor(proxy, index) { if (!isLoon && !isSurge) throw new Error('仅支持 Loon 和 Surge(ability=http-client-policy)'); const node = ProxyUtils.produce([proxy], isLoon ? 'Loon' : 'Surge'); + if (!node) throw new Error('当前客户端不兼容此节点'); const monitors = proxy._monitors || [ { name: 'Cloudflare',