Skip to content

Commit

Permalink
!271 调整压缩包 获取路径方法
Browse files Browse the repository at this point in the history
Merge pull request !271 from 高雄/master
  • Loading branch information
klboke authored and gitee-org committed Mar 6, 2024
2 parents 3482ee5 + e79c531 commit 787e9fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
11 changes: 3 additions & 8 deletions server/src/main/java/cn/keking/service/FileHandlerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
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;
Expand Down Expand Up @@ -432,7 +430,8 @@ public FileAttribute getFileAttribute(String url, HttpServletRequest req) {
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);
Expand All @@ -453,14 +452,10 @@ public FileAttribute getFileAttribute(String url, HttpServletRequest req) {
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();
}
Expand Down
6 changes: 2 additions & 4 deletions server/src/main/resources/web/compress.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 787e9fe

Please sign in to comment.