From 1992c1f52df1dda2ea452902391600916fa21137 Mon Sep 17 00:00:00 2001 From: zhaojun <873019219@qq.com> Date: Wed, 13 Jul 2022 20:11:50 +0800 Subject: [PATCH] =?UTF-8?q?:memo:=20=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=83=85=E5=86=B5=E7=9A=84=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zfile/home/filter/DownloadLinkFilter.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/im/zhaojun/zfile/home/filter/DownloadLinkFilter.java b/src/main/java/im/zhaojun/zfile/home/filter/DownloadLinkFilter.java index dc77a73..4056d74 100644 --- a/src/main/java/im/zhaojun/zfile/home/filter/DownloadLinkFilter.java +++ b/src/main/java/im/zhaojun/zfile/home/filter/DownloadLinkFilter.java @@ -18,7 +18,7 @@ import im.zhaojun.zfile.admin.service.StorageSourceService; import im.zhaojun.zfile.admin.service.SystemConfigService; import im.zhaojun.zfile.common.constant.ZFileConstant; import im.zhaojun.zfile.common.context.StorageSourceContext; -import im.zhaojun.zfile.common.exception.NotEnabledStorageSourceException; +import im.zhaojun.zfile.common.exception.InvalidStorageSourceException; import im.zhaojun.zfile.common.exception.file.operator.DownloadFileException; import im.zhaojun.zfile.common.util.HttpUtil; import im.zhaojun.zfile.common.util.StringUtils; @@ -174,14 +174,25 @@ public class DownloadLinkFilter implements Filter { StorageSource storageSource = storageSourceService.findByStorageKey(storageKey); Boolean enable = storageSource.getEnable(); if (!enable) { - throw new NotEnabledStorageSourceException(); + log.error("存储源当前状态为未启用,仍然请求下载,存储源 key {}, 文件路径 {}", storageKey, filePath); + response.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain;charset=utf-8"); + response.getWriter().write("当前存储源未启用, 无法下载,请联系管理员!"); + return; } if (filePath.length() > 0 && filePath.charAt(0) != ZFileConstant.PATH_SEPARATOR_CHAR) { filePath = "/" + filePath; } - AbstractBaseFileService fileService = storageSourceContext.getByKey(storageKey); + AbstractBaseFileService fileService; + try { + fileService = storageSourceContext.getByKey(storageKey); + } catch (InvalidStorageSourceException e) { + log.error("无效的存储源,存储源 key {}, 文件路径 {}", storageKey, filePath); + response.setHeader(HttpHeaders.CONTENT_TYPE, "text/plain;charset=utf-8"); + response.getWriter().write("无效的或初始化失败的存储源, 请联系管理员!"); + return; + } String downloadUrl; try {