From 6dcdfe4d23c309ca5cd461f64214118ea7c3a9f6 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 17 Dec 2025 15:55:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=BF=94=E5=9B=9E=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UploadDownLoadController.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs index 77b57270c..259aaaea9 100644 --- a/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs +++ b/IRaCIS.Core.API/Controllers/UploadDownLoadController.cs @@ -916,12 +916,29 @@ namespace IRaCIS.Core.API.Controllers var notifyInterval = TimeSpan.FromSeconds(1); var lastNotify = DateTime.UtcNow; + // 用于计算下载速度 + long lastReceivedSize = 0; + DateTime lastSpeedCheck = DateTime.UtcNow; async Task NotifyProgressAsync(bool force = false) { - if (!force && DateTime.UtcNow - lastNotify < notifyInterval) + + var now = DateTime.UtcNow; + var elapsedSeconds = (now - lastSpeedCheck).TotalSeconds; + + // 如果没有强制推送,并且未到推送间隔,则返回 + if (!force && elapsedSeconds < notifyInterval.TotalSeconds) return; + // 计算下载速度(字节/秒) + double speedBps = 0; + if (elapsedSeconds > 0) + { + speedBps = (receivedSize - lastReceivedSize) / elapsedSeconds; + } + + lastSpeedCheck = now; + lastReceivedSize = receivedSize; lastNotify = DateTime.UtcNow; var progress = new @@ -932,7 +949,11 @@ namespace IRaCIS.Core.API.Controllers SizePercent = totalSize > 0 ? Math.Round(receivedSize * 100m / totalSize, 2).ToString() + "%" - : "0%" + : "0%", + + Speed = (speedBps / 1024 >= 1024 + ? (speedBps / 1024 / 1024).ToString("0.00") + " MB/s" + : (speedBps / 1024).ToString("0.00") + " KB/s") }; // 不阻塞下载流程