From 27ed834c09a217eeac58faba23e82d334d5b5acd Mon Sep 17 00:00:00 2001 From: aipper Date: Wed, 26 Nov 2025 18:37:50 +0800 Subject: [PATCH] test --- .../controller/ArchiveFileController.java | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/point/strategy/archiveFile/controller/ArchiveFileController.java b/src/main/java/com/point/strategy/archiveFile/controller/ArchiveFileController.java index 21bcc6e..ede5c02 100644 --- a/src/main/java/com/point/strategy/archiveFile/controller/ArchiveFileController.java +++ b/src/main/java/com/point/strategy/archiveFile/controller/ArchiveFileController.java @@ -370,40 +370,16 @@ public class ArchiveFileController { String downLoadPath = path + fileNameServer; String[] strings = fileName.split("\\."); String type = strings[strings.length - 1]; + boolean processedFromLocal = false; - // 检查是否通过URL访问 - if (url != null && !url.isEmpty()) { - // 使用流式处理,避免完整下载 - try { - URL url1 = new URL(url); - HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection(); - urlConnection.setConnectTimeout(10000); // 10秒超时 - urlConnection.setReadTimeout(10000); - urlConnection.connect(); - - if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { - try (InputStream inputStream = urlConnection.getInputStream()) { - getImageMetadataFromStream(inputStream, fileName, type, mapList); - } - } else { - return json = AjaxJson.returnExceptionInfo("无法访问图片URL: " + url); - } - } catch (Exception e) { - log.error("处理URL图片失败: {}", e.getMessage()); - return json = AjaxJson.returnExceptionInfo("处理URL图片失败: " + e.getMessage()); - } - } else { - // 处理本地文件 - File file = new File(downLoadPath); - if (!file.exists()) { - return json = AjaxJson.returnExceptionInfo("文件不存在: " + downLoadPath); - } - - try (InputStream inputStream = new FileInputStream(file)) { + // 优先处理本地文件 + File localFile = new File(downLoadPath); + if (localFile.exists()) { + try (InputStream inputStream = new FileInputStream(localFile)) { getImageMetadataFromStream(inputStream, fileName, type, mapList); // 获取文件大小 - int length = (int) (file.length() / 1024); + int length = (int) (localFile.length() / 1024); VideoInfoUtils.setMapList("大小","length",length + "kb",mapList); // 判断是否数字加密了 @@ -419,12 +395,41 @@ public class ArchiveFileController { VideoInfoUtils.setMapList("数据加密", "signatureData", signatureMap.get("signatureData"), mapList); } } + processedFromLocal = true; + log.info("成功从本地文件读取图片元数据: {}", downLoadPath); } catch (Exception e) { log.error("处理本地图片失败: {}", e.getMessage()); - return json = AjaxJson.returnExceptionInfo("处理本地图片失败: " + e.getMessage()); + processedFromLocal = false; } } + // 如果本地文件不存在或处理失败,且提供了URL,则尝试从URL处理 + if (!processedFromLocal && url != null && !url.isEmpty()) { + log.info("本地文件不存在或处理失败,尝试从URL读取: {}", url); + try { + URL url1 = new URL(url); + HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection(); + urlConnection.setConnectTimeout(10000); // 10秒超时 + urlConnection.setReadTimeout(10000); + urlConnection.connect(); + + if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { + try (InputStream inputStream = urlConnection.getInputStream()) { + getImageMetadataFromStream(inputStream, fileName, type, mapList); + } + log.info("成功从URL读取图片元数据: {}", url); + } else { + return json = AjaxJson.returnExceptionInfo("无法访问图片URL: " + url + ",响应码: " + urlConnection.getResponseCode()); + } + } catch (Exception e) { + log.error("处理URL图片失败: {}", e.getMessage()); + return json = AjaxJson.returnExceptionInfo("处理URL图片失败: " + e.getMessage()); + } + } else if (!processedFromLocal) { + // 本地文件不存在且没有提供URL + return json = AjaxJson.returnExceptionInfo("文件不存在: " + downLoadPath); + } + json.put("list", mapList); }