From 82acda9e2442cd62bb7a142edc888688629abf24 Mon Sep 17 00:00:00 2001 From: ye1023 <12588209+ye1023@user.noreply.gitee.com> Date: Tue, 21 Jul 2026 10:07:57 +0800 Subject: [PATCH] =?UTF-8?q?yxk-20260721=20bug=E4=BF=AE=E5=A4=8D=EF=BC=8Ckk?= =?UTF-8?q?=E7=9A=84=E5=9C=A8=E7=BA=BF=E9=A2=84=E8=A7=88=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=9A=E5=8E=9F=E5=9B=A0=E6=98=AF=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=89=8D=E5=90=8E=E7=AB=AF=E9=9A=94=E7=A6=BB=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E9=85=8D=E7=BD=AE=E8=BF=98=E6=98=AFlocalhost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/FileController.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java index 6666b95..6270e92 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/FileController.java @@ -58,6 +58,8 @@ public class FileController { private BaseCommonService baseCommonService; @Value(value = "${jeecg.appName}") private String applicationName; + @Value(value = "${jeecg.file-preview-download-domain:}") + private String filePreviewDownloadDomain; private static final String FILE_PREVIEW_REDIS_PREFIX = "sys:file:preview:"; private static final long FILE_PREVIEW_TOKEN_EXPIRE_SECONDS = 600L; @@ -619,7 +621,22 @@ public class FileController { private String buildPreviewDownloadUrl(HttpServletRequest request, String token, String fileName) { // kkFileView judges the preview handler by file suffix; stream APIs without suffix need fullfilename. - return buildRequestBaseUrl(request) + "/sys/file/previewDownload?token=" + token + "&fullfilename=" + encodeUrlParam(fileName); + return getPreviewDownloadBaseUrl(request) + "/sys/file/previewDownload?token=" + token + "&fullfilename=" + encodeUrlParam(fileName); + } + + private String getPreviewDownloadBaseUrl(HttpServletRequest request) { + if (!StringUtils.isEmpty(filePreviewDownloadDomain) && !StringUtils.isEmpty(filePreviewDownloadDomain.trim())) { + // kkFileView may run on another host, so its download address must not depend on proxy headers. + return trimTrailingSlash(filePreviewDownloadDomain.trim()); + } + return buildRequestBaseUrl(request); + } + + private String trimTrailingSlash(String value) { + while (value.endsWith("/")) { + value = value.substring(0, value.length() - 1); + } + return value; } private JSONObject parsePreviewInfo(Object cache) {