Переглянути джерело

不支持文件支持点击下载

chenzl 10 місяців тому
батько
коміт
72b0b5eb67

+ 2 - 2
server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java

@@ -47,7 +47,7 @@ public class CadFilePreviewImpl implements FilePreview {
         if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(cacheName) || !ConfigConstants.isCacheEnabled()) {
             ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
             if (response.isFailure()) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
             }
             String filePath = response.getContent();
             String imageUrls = null;
@@ -58,7 +58,7 @@ public class CadFilePreviewImpl implements FilePreview {
                     e.printStackTrace();
                 }
                 if (imageUrls == null) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, "office转图片异常,请联系管理员");
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, "office转图片异常,请联系管理员");
                 }
                 //是否保留CAD源文件
                 if (!fileAttribute.isCompressFile() && ConfigConstants.getDeleteSourceFile()) {

+ 1 - 1
server/src/main/java/cn/keking/service/impl/CommonPreviewImpl.java

@@ -35,7 +35,7 @@ public class CommonPreviewImpl implements FilePreview {
         if (url != null && !url.toLowerCase().startsWith("http")) {
             ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, null);
             if (response.isFailure()) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
             } else {
                 String file = fileHandlerService.getRelativePath(response.getContent());
                 model.addAttribute("currentUrl", file);

+ 2 - 2
server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java

@@ -44,7 +44,7 @@ public class CompressFilePreviewImpl implements FilePreview {
         if (forceUpdatedCache || !StringUtils.hasText(fileHandlerService.getConvertedFile(fileName))  || !ConfigConstants.isCacheEnabled()) {
             ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
             if (response.isFailure()) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
             }
             String filePath = response.getContent();
             try {
@@ -70,7 +70,7 @@ public class CompressFilePreviewImpl implements FilePreview {
                     fileHandlerService.addConvertedFile(fileName, fileTree);
                 }
             }else {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件密码错误! 压缩文件损坏!  压缩文件类型不受支持!");
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, "压缩文件密码错误! 压缩文件损坏!  压缩文件类型不受支持!");
             }
         } else {
             fileTree = fileHandlerService.getConvertedFile(fileName);

+ 3 - 3
server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java

@@ -55,7 +55,7 @@ public class MediaFilePreviewImpl implements FilePreview {
             if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(cacheName) || !ConfigConstants.isCacheEnabled()) {  //查询是否开启缓存
                 ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
                 if (response.isFailure()) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
                 }
                 String filePath = response.getContent();
                 String convertedUrl = null;
@@ -69,7 +69,7 @@ public class MediaFilePreviewImpl implements FilePreview {
                     e.printStackTrace();
                 }
                 if (convertedUrl == null) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, "视频转换异常,请联系管理员");
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, "视频转换异常,请联系管理员");
                 }
                 if (ConfigConstants.isCacheEnabled()) {
                     // 加入缓存
@@ -85,7 +85,7 @@ public class MediaFilePreviewImpl implements FilePreview {
             model.addAttribute("mediaUrl", url);
             return MEDIA_FILE_PREVIEW_PAGE;
         }
-        return otherFilePreview.notSupportedFile(model, fileAttribute, "系统还不支持该格式文件的在线预览");
+        return otherFilePreview.notSupportedFile(url, model, fileAttribute, "系统还不支持该格式文件的在线预览");
     }
 
     /**

+ 3 - 3
server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java

@@ -71,7 +71,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
         // 下载远程文件到本地,如果文件在本地已存在不会重复下载
         ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
         if (response.isFailure()) {
-            return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+            return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
         }
             String filePath = response.getContent();
             boolean  isPwdProtectedOffice =  OfficeUtils.isPwdProtected(filePath);    // 判断是否加密文件
@@ -90,7 +90,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
                             model.addAttribute("filePasswordError", true);
                             return EXEL_FILE_PREVIEW_PAGE;
                         }
-                        return otherFilePreview.notSupportedFile(model, fileAttribute, "抱歉,该文件版本不兼容,文件版本错误。");
+                        return otherFilePreview.notSupportedFile(url, model, fileAttribute, "抱歉,该文件版本不兼容,文件版本错误。");
                     }
                     if (isHtmlView) {
                         // 对转换后的文件进行操作(改变编码方式)
@@ -133,7 +133,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
             }
         }
         if (imageUrls == null || imageUrls.size() < 1) {
-            return otherFilePreview.notSupportedFile(model, fileAttribute, "office转图片异常,请联系管理员");
+            return otherFilePreview.notSupportedFile(null, model, fileAttribute, "office转图片异常,请联系管理员");
         }
         model.addAttribute("imgUrls", imageUrls);
         model.addAttribute("currentUrl", imageUrls.get(0));

+ 8 - 6
server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java

@@ -16,16 +16,17 @@ public class OtherFilePreviewImpl implements FilePreview {
 
     @Override
     public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
-        return this.notSupportedFile(model, fileAttribute, "系统还不支持该格式文件的在线预览");
+        return this.notSupportedFile(url, model, fileAttribute, "系统还不支持该格式文件的在线预览");
     }
 
     /**
      * 通用的预览失败,导向到不支持的文件响应页面
      *
      * @return 页面
+     * todo 方法改成传url进来,页面上显示点击下载的超链接
      */
-    public String notSupportedFile(Model model, FileAttribute fileAttribute, String errMsg) {
-        return this.notSupportedFile(model, fileAttribute.getSuffix(), errMsg);
+    public String notSupportedFile(String url, Model model, FileAttribute fileAttribute, String errMsg) {
+        return this.notSupportedFile(url, model, fileAttribute.getSuffix(), errMsg);
     }
 
     /**
@@ -33,8 +34,8 @@ public class OtherFilePreviewImpl implements FilePreview {
      *
      * @return 页面
      */
-    public String notSupportedFile(Model model, String errMsg) {
-        return this.notSupportedFile(model, "未知", errMsg);
+    public String notSupportedFile(String url, Model model, String errMsg) {
+        return this.notSupportedFile(url, model, "未知", errMsg);
     }
 
     /**
@@ -42,9 +43,10 @@ public class OtherFilePreviewImpl implements FilePreview {
      *
      * @return 页面
      */
-    public String notSupportedFile(Model model, String fileType, String errMsg) {
+    public String notSupportedFile(String url, Model model, String fileType, String errMsg) {
         model.addAttribute("fileType",  KkFileUtils.htmlEscape(fileType));
         model.addAttribute("msg", KkFileUtils.htmlEscape(errMsg));
+        model.addAttribute("url", url);
         return NOT_SUPPORTED_FILE_PAGE;
     }
 

+ 4 - 4
server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java

@@ -41,7 +41,7 @@ public class PdfFilePreviewImpl implements FilePreview {
             if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
                 ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, pdfName);
                 if (response.isFailure()) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
                 }
                 originFilePath = response.getContent();
                 if (ConfigConstants.isCacheEnabled()) {
@@ -62,10 +62,10 @@ public class PdfFilePreviewImpl implements FilePreview {
                         }
                     }
                 }
-                return otherFilePreview.notSupportedFile(model, fileAttribute, "pdf转图片异常,请联系管理员");
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, "pdf转图片异常,请联系管理员");
             }
             if (imageUrls == null || imageUrls.size() < 1) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, "pdf转图片异常,请联系管理员");
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, "pdf转图片异常,请联系管理员");
             }
             model.addAttribute("imgUrls", imageUrls);
             model.addAttribute("currentUrl", imageUrls.get(0));
@@ -80,7 +80,7 @@ public class PdfFilePreviewImpl implements FilePreview {
                 if (!fileHandlerService.listConvertedFiles().containsKey(pdfName) || !ConfigConstants.isCacheEnabled()) {
                     ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, pdfName);
                     if (response.isFailure()) {
-                        return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                        return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
                     }
                     model.addAttribute("pdfUrl", fileHandlerService.getRelativePath(response.getContent()));
                     if (ConfigConstants.isCacheEnabled()) {

+ 2 - 2
server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java

@@ -39,7 +39,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
         if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(fileName) || !ConfigConstants.isCacheEnabled()) {
             ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
             if (response.isFailure()) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
             }
             filePath = response.getContent();
             if (ConfigConstants.isCacheEnabled()) {
@@ -49,7 +49,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
                 String  fileData = HtmlUtils.htmlEscape(textData(filePath,fileName));
                 model.addAttribute("textData", Base64.encodeBase64String(fileData.getBytes()));
             } catch (IOException e) {
-                return otherFilePreview.notSupportedFile(model, fileAttribute, e.getLocalizedMessage());
+                return otherFilePreview.notSupportedFile(url, model, fileAttribute, e.getLocalizedMessage());
             }
             return TXT_FILE_PREVIEW_PAGE;
         }

+ 4 - 4
server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java

@@ -41,7 +41,7 @@ public class TiffFilePreviewImpl implements FilePreview {
             if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(cacheName) || !ConfigConstants.isCacheEnabled()) {
                 ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
                 if (response.isFailure()) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
                 }
                 String filePath = response.getContent();
                 if ("pdf".equalsIgnoreCase(tifPreviewType)) {
@@ -53,7 +53,7 @@ public class TiffFilePreviewImpl implements FilePreview {
                             model.addAttribute("currentUrl", url);
                             return PICTURE_FILE_PREVIEW_PAGE;
                         }else {
-                            return otherFilePreview.notSupportedFile(model, fileAttribute, "TIF转pdf异常,请联系系统管理员!" );
+                            return otherFilePreview.notSupportedFile(url, model, fileAttribute, "TIF转pdf异常,请联系系统管理员!" );
                         }
                     }
                     //是否保留TIFF源文件
@@ -77,7 +77,7 @@ public class TiffFilePreviewImpl implements FilePreview {
                             model.addAttribute("currentUrl", url);
                             return PICTURE_FILE_PREVIEW_PAGE;
                         }else {
-                            return otherFilePreview.notSupportedFile(model, fileAttribute, "TIF转JPG异常,请联系系统管理员!" );
+                            return otherFilePreview.notSupportedFile(url, model, fileAttribute, "TIF转JPG异常,请联系系统管理员!" );
                         }
                     }
                     //是否保留源文件,转换失败保留源文件,转换成功删除源文件
@@ -109,7 +109,7 @@ public class TiffFilePreviewImpl implements FilePreview {
             if (forceUpdatedCache || !fileHandlerService.listConvertedFiles().containsKey(fileName) || !ConfigConstants.isCacheEnabled()) {
                 ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
                 if (response.isFailure()) {
-                    return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
+                    return otherFilePreview.notSupportedFile(url, model, fileAttribute, response.getMsg());
                 }
                 model.addAttribute("currentUrl", fileHandlerService.getRelativePath(response.getContent()));
                 if (ConfigConstants.isCacheEnabled()) {

+ 2 - 2
server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java

@@ -62,7 +62,7 @@ public class OnlinePreviewController {
             fileUrl = WebUtils.decodeUrl(url);
         } catch (Exception ex) {
             String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "url");
-            return otherFilePreview.notSupportedFile(model, errorMsg);
+            return otherFilePreview.notSupportedFile(url, model, errorMsg);
         }
         FileAttribute fileAttribute = fileHandlerService.getFileAttribute(fileUrl, req);
         model.addAttribute("file", fileAttribute);
@@ -80,7 +80,7 @@ public class OnlinePreviewController {
             fileUrls = KkFileUtils.htmlEscape(fileUrls);
         } catch (Exception ex) {
             String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "urls");
-            return otherFilePreview.notSupportedFile(model, errorMsg);
+            return otherFilePreview.notSupportedFile(null, model, errorMsg);
         }
         logger.info("预览文件url:{},urls:{}", fileUrls, urls);
         // 抽取文件并返回文件列表

BIN
server/src/main/resources/static/images/sorry.jpg


+ 10 - 1
server/src/main/resources/web/fileNotSupported.ftl

@@ -33,11 +33,20 @@
 
 <body>
 <div class="container">
-    <img src="images/sorry.jpg"/>
+<#--    <img src="images/sorry.jpg"/>-->
+    <div style="height: 200px"></div>
     <span>
         该(${fileType})文件,系统暂不支持在线预览,具体原因如下:
         <p style="color: red;">${msg}</p>
     </span>
+    <#if url??>
+        <span>
+            如需下载,您可
+            <a href="${url}">点击下载</a>
+        </span>
+        
+    </#if>
+    
 </div>
 </body>
 </html>

+ 2 - 1
server/src/main/resources/web/notTrustDir.html

@@ -32,7 +32,8 @@
 </head>
 <body>
 <div class="container">
-    <img src="images/sorry.jpg" />
+<!--    <img src="images/sorry.jpg" />-->
+    <div style="height: 200px"></div>
     <p>
         预览源文件来自未授信的目录,请停止访问!<br>
     </p>

+ 2 - 1
server/src/main/resources/web/notTrustHost.html

@@ -32,7 +32,8 @@
 </head>
 <body>
 <div class="container">
-    <img src="images/sorry.jpg" />
+<!--    <img src="images/sorry.jpg" />-->
+    <div style="height: 200px"></div>
     <p>
         预览源文件来自不受信任的站点:<span style="color: red; display: inline;">${current_host}</span> 请联系管理员!<br>
     </p>

+ 2 - 1
server/src/main/resources/web/tiff.ftl

@@ -100,7 +100,8 @@ html += "</head>";
 html += "";
 html += "<body>";
 html += "<div class=\"container\">";
-html += "    <img src=\"images/sorry.jpg\"/>";
+// html += "    <img src=\"images/sorry.jpg\"/>";
+html += "    <div style=\"height: 200px\"></div>";
 html += "    <span>";
 html += "        该(tif)文件,系统解析错误,具体原因如下:";
 html += "        <p style=\"color: red;\">文件[${file.name}]解析失败,请联系系统管理员</p>";