From c7329c32eb1022e8ccb6e1ba790ff7c5c6cfed87 Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 19 Apr 2024 06:27:45 +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=94=AF?= =?UTF-8?q?=E6=8C=81=E7=94=A8=E5=8F=82=E6=95=B0=E4=BC=A0=E5=85=A5=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=AC=A1=E6=95=B0;=20=E8=8A=82=E7=82=B9=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=8A=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E6=AC=A1=E6=95=B0,=20=E5=8F=AA=E5=8F=96=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/restful/download.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index 3b94344..ceee983 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -176,7 +176,11 @@ async function downloadSubscription(req, res) { nezhaIndex = /^\d+$/.test(nezhaIndex) ? parseInt(nezhaIndex, 10) : output.findIndex((i) => i.name === nezhaIndex); - output = await nezhaMonitor(output[nezhaIndex], nezhaIndex); + output = await nezhaMonitor( + output[nezhaIndex], + nezhaIndex, + req.query, + ); } res.set('Content-Type', 'application/json;charset=utf-8').send( output, @@ -327,7 +331,11 @@ async function downloadCollection(req, res) { nezhaIndex = /^\d+$/.test(nezhaIndex) ? parseInt(nezhaIndex, 10) : output.findIndex((i) => i.name === nezhaIndex); - output = await nezhaMonitor(output[nezhaIndex], nezhaIndex); + output = await nezhaMonitor( + output[nezhaIndex], + nezhaIndex, + req.query, + ); } res.set('Content-Type', 'application/json;charset=utf-8').send( output, @@ -366,7 +374,7 @@ async function downloadCollection(req, res) { } } -async function nezhaMonitor(proxy, index) { +async function nezhaMonitor(proxy, index, query) { const result = { code: 0, message: 'success', @@ -395,7 +403,8 @@ async function nezhaMonitor(proxy, index) { timeout: 2000, }, ]; - + const number = + query.number || Math.max(...monitors.map((i) => i.number)) || 3; for (const monitor of monitors) { const interval = 10 * 60 * 1000; const data = { @@ -406,8 +415,7 @@ async function nezhaMonitor(proxy, index) { created_at: [], avg_delay: [], }; - - for (let index = 0; index < monitor.number; index++) { + for (let index = 0; index < number; index++) { const startedAt = Date.now(); try { await $.http[(monitor.method || 'HEAD').toLowerCase()]({