From 1693d904c458699be91741476f09932f0906a1a0 Mon Sep 17 00:00:00 2001 From: linwumingshi Date: Mon, 28 Jul 2025 17:38:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E4=BF=AE=E5=A4=8D=E4=BA=91?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=A0=BC=E5=BC=8F=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新了 CloudRecordUtils 类,使其使用 UtilityClass 注解 - 优化了 getDownloadFilePath 方法,将文件路径作为独立参数传入 - 修复了原始实现中可能导致路径格式错误的问题 - 增加了方法注释,说明其功能和参数 --- .../iot/vmp/utils/CloudRecordUtils.java | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java b/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java index 10cb620b9..6fcf53b3f 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/CloudRecordUtils.java @@ -2,21 +2,45 @@ package com.genersoft.iot.vmp.utils; import com.genersoft.iot.vmp.media.bean.MediaServer; import com.genersoft.iot.vmp.service.bean.DownloadFileInfo; +import lombok.experimental.UtilityClass; +/** + * 云录像工具类 + * + * @author 648540858 + */ +@UtilityClass public class CloudRecordUtils { + + /** + * 修复原始工具类中的格式化问题 + * + * @param mediaServerItem 媒体服务器配置 + * @param filePath 文件路径(可能包含%等特殊字符) + * @return 修复后的下载信息 + */ public static DownloadFileInfo getDownloadFilePath(MediaServer mediaServerItem, String filePath) { - DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); + // 将filePath作为独立参数传入,避免%符号解析问题 + String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=%s"; - String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; + DownloadFileInfo info = new DownloadFileInfo(); - downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), - mediaServerItem.getHttpPort())); + // filePath作为第4个参数 + info.setHttpPath(String.format(pathTemplate, + "http", + mediaServerItem.getStreamIp(), + mediaServerItem.getHttpPort(), + filePath)); + // 同样作为第4个参数 if (mediaServerItem.getHttpSSlPort() > 0) { - downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), - mediaServerItem.getHttpSSlPort())); + info.setHttpsPath(String.format(pathTemplate, + "https", + mediaServerItem.getStreamIp(), + mediaServerItem.getHttpSSlPort(), + filePath)); } - return downloadFileInfo; + return info; } }