Browse Source

!271 调整压缩包 获取路径方法
Merge pull request !271 from 高雄/master

kailing 1 year ago
parent
commit
787e9fe615

+ 3 - 8
server/src/main/java/cn/keking/service/FileHandlerService.java

@@ -37,8 +37,6 @@ import org.springframework.util.StringUtils;
 import javax.servlet.http.HttpServletRequest;
 import java.awt.image.BufferedImage;
 import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
@@ -432,7 +430,8 @@ public class FileHandlerService implements InitializingBean {
         String outFilePath; //生成文件的路径
         String originFilePath; //原始文件路径
         String fullFileName = WebUtils.getUrlParameterReg(url, "fullfilename");
-        String compressFileKey = WebUtils.getUrlParameterReg(url, "kkCompressfileKey"); //压缩包指定特殊符号
+        String compressFileKey = WebUtils.getUrlParameterReg(url, "kkCompressfileKey"); //压缩包获取文件名
+        String compressFilePath = WebUtils.getUrlParameterReg(url, "kkCompressfilepath"); //压缩包获取文件路径
         if (StringUtils.hasText(fullFileName)) {
             originFileName = fullFileName;
             type = FileType.typeFromFileName(fullFileName);
@@ -453,14 +452,10 @@ public class FileHandlerService implements InitializingBean {
             try {
                 // http://127.0.0.1:8012/各类型文件1 - 副本.zip_/各类型文件/正常预览/PPT转的PDF.pdf?kkCompressfileKey=各类型文件1 - 副本.zip_
                 // http://127.0.0.1:8012/preview/各类型文件1 - 副本.zip_/各类型文件/正常预览/PPT转的PDF.pdf?kkCompressfileKey=各类型文件1 - 副本.zip_ 获取路径就会错误 需要下面的方法
-                URL urll = new URL(url);
-                String _Path = urll.getPath(); //获取url路径
-                String urlStrr = getSubString(_Path, compressFileKey); //反代情况下添加前缀,只获取有压缩包字符的路径
+                String urlStrr = getSubString(compressFilePath, compressFileKey); //反代情况下添加前缀,只获取有压缩包字符的路径
                 originFileName = compressFileKey + urlStrr.trim(); //拼接完整路径
                 originFileName = URLDecoder.decode(originFileName, uriEncoding); //压缩包文件中文编码问题
                 attribute.setSkipDownLoad(true);
-            } catch (MalformedURLException e) {
-                e.printStackTrace();
             } catch (UnsupportedEncodingException e) {
                 e.printStackTrace();
             }

+ 2 - 4
server/src/main/resources/web/compress.ftl

@@ -49,17 +49,15 @@
             onClick: chooseNode,
         }
     };
-
     function chooseNode(event, treeId, treeNode) {
         if (!treeNode.isParent) {
-            var path = '${baseUrl}' + treeNode.id + "?kkCompressfileKey=" + '${fileTree}';
+            var path = '${baseUrl}' + treeNode.id + "?kkCompressfileKey=" + '${fileTree}'+"&kkCompressfilepath=" + treeNode.id+"&fullfilename="+treeNode.name;
             location.href = "${baseUrl}onlinePreview?url=" + encodeURIComponent(Base64.encode(path));
         }
     }
-
     $(document).ready(function () {
     var url = '${fileTree}';
-        $.ajax({
+       $.ajax({
             type: "get",
             url: "${baseUrl}directory?urls="+encodeURIComponent(Base64.encode(url)),
             success: function (res) {