修复压缩获取路径错误,图片合集路径错误,水印问题等BUG
This commit is contained in:
parent
0a4ae41b0c
commit
48ac926289
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -48,7 +49,6 @@ public class CompressFileReader {
|
|||
if (fileAttribute.isCompressFile()) {
|
||||
folderName = "_decompression" + folderName;
|
||||
}
|
||||
|
||||
Path folderPath = Paths.get(fileDir, folderName + packagePath);
|
||||
Files.createDirectories(folderPath);
|
||||
|
||||
|
@ -67,14 +67,18 @@ public class CompressFileReader {
|
|||
}
|
||||
return data.length;
|
||||
}, filePassword);
|
||||
|
||||
if (result != ExtractOperationResult.OK) {
|
||||
throw new Exception("Failed to extract RAR file.");
|
||||
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
|
||||
if (result1.equals(result)) {
|
||||
throw new Exception("Password");
|
||||
}else {
|
||||
throw new Exception("Failed to extract RAR file.");
|
||||
}
|
||||
}
|
||||
|
||||
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
|
||||
if (type.equals(FileType.PICTURE)) {
|
||||
imgUrls.add(baseUrl + folderPath.relativize(filePathInsideArchive).toString().replace("\\", "/"));
|
||||
if (type.equals(FileType.PICTURE)) { //图片缓存到集合,为了特殊符号需要进行编码
|
||||
imgUrls.add(baseUrl + URLEncoder.encode(fileName + packagePath+"/"+ folderPath.relativize(filePathInsideArchive).toString().replace("\\", "/"), "UTF-8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,4 +110,4 @@ public class CompressFileReader {
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -474,11 +474,7 @@ public class FileHandlerService implements InitializingBean {
|
|||
boolean isCompressFile = !ObjectUtils.isEmpty(compressFileKey);
|
||||
if (isCompressFile) { //判断是否使用特定压缩包符号
|
||||
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_ 获取路径就会错误 需要下面的方法
|
||||
String urlStrr = getSubString(compressFilePath, compressFileKey); //反代情况下添加前缀,只获取有压缩包字符的路径
|
||||
originFileName = compressFileKey + urlStrr.trim(); //拼接完整路径
|
||||
originFileName = URLDecoder.decode(originFileName, uriEncoding); //压缩包文件中文编码问题
|
||||
originFileName = URLDecoder.decode(originFileName, uriEncoding); //转义的文件名 解下出原始文件名
|
||||
attribute.setSkipDownLoad(true);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -54,15 +54,11 @@ public class CompressFilePreviewImpl implements FilePreview {
|
|||
try {
|
||||
fileTree = compressFileReader.unRar(filePath, filePassword, fileName, fileAttribute);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error processing RAR file: " + e.getMessage(), e);
|
||||
Throwable[] throwableArray = ExceptionUtils.getThrowables(e);
|
||||
for (Throwable throwable : throwableArray) {
|
||||
if (throwable instanceof IOException || throwable instanceof EncryptedDocumentException) {
|
||||
if (e.getMessage().toLowerCase().contains(Rar_PASSWORD_MSG)) {
|
||||
model.addAttribute("needFilePassword", true);
|
||||
return EXEL_FILE_PREVIEW_PAGE;
|
||||
}
|
||||
}
|
||||
if (e.getMessage().toLowerCase().contains(Rar_PASSWORD_MSG)) {
|
||||
model.addAttribute("needFilePassword", true);
|
||||
return EXEL_FILE_PREVIEW_PAGE;
|
||||
}else {
|
||||
logger.error("Error processing RAR file: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(fileTree)) {
|
||||
|
|
|
@ -77,7 +77,7 @@ public class RarUtils {
|
|||
}
|
||||
public static String specialSymbols(String str) {
|
||||
//去除压缩包文件字符串中特殊符号
|
||||
Pattern p = Pattern.compile("\\s|\t|\r|\n|\\+|#|&|=|\\p{P}");
|
||||
Pattern p = Pattern.compile("\\s|\t|\r|\n|\\+|#|&|=|<EFBFBD>|\\p{P}");
|
||||
// Pattern p = Pattern.compile("\\s|\\+|#|&|=|\\p{P}");
|
||||
Matcher m = p.matcher(str);
|
||||
return m.replaceAll("");
|
||||
|
|
|
@ -213,6 +213,7 @@ public class FileController {
|
|||
String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "url");
|
||||
return ReturnResponse.failure(errorMsg);
|
||||
}
|
||||
fileUrl = fileUrl.replaceAll("http://", "");
|
||||
if (KkFileUtils.isIllegalFileName(fileUrl)) {
|
||||
return ReturnResponse.failure("不允许访问的路径:");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>压缩包预览</title>
|
||||
<title>${file.name}压缩包预览</title>
|
||||
<script src="js/jquery-3.6.1.min.js"></script>
|
||||
<#include "*/commonHeader.ftl">
|
||||
<script src="js/base64.min.js" type="text/javascript"></script>
|
||||
|
@ -49,14 +49,28 @@
|
|||
onClick: chooseNode,
|
||||
}
|
||||
};
|
||||
|
||||
function isNotEmpty(value) {
|
||||
return value !== null && value !== undefined && value !== '' && value !== 0 && !(value instanceof Array && value.length === 0) && !isNaN(value);
|
||||
}
|
||||
function getQueryParam(url, param) {
|
||||
var urlObj = new URL(url);
|
||||
return urlObj.searchParams.get(param);
|
||||
}
|
||||
var currentUrl = window.location.href;
|
||||
var keyword = getQueryParam(currentUrl, 'watermarkTxt');
|
||||
function chooseNode(event, treeId, treeNode) {
|
||||
if (!treeNode.isParent) {
|
||||
var path = '${baseUrl}' + treeNode.id + "?kkCompressfileKey=" + encodeURIComponent('${fileTree}')+"&kkCompressfilepath=" + encodeURIComponent(treeNode.id)+"&fullfilename="+encodeURIComponent(treeNode.name);
|
||||
location.href = "${baseUrl}onlinePreview?url=" + encodeURIComponent(Base64.encode(path));
|
||||
var path = '${baseUrl}'+encodeURIComponent(treeNode.id)+"?kkCompressfileKey="+'${fileTree}'+"&kkCompressfilepath="+encodeURIComponent(treeNode.id)+"&fullfilename="+encodeURIComponent(treeNode.name);
|
||||
if (isNotEmpty(keyword)){
|
||||
location.href = "${baseUrl}onlinePreview?url=" + encodeURIComponent(Base64.encode(path))+"&watermarkTxt="+keyword;
|
||||
}else{
|
||||
location.href = "${baseUrl}onlinePreview?url=" + encodeURIComponent(Base64.encode(path));}
|
||||
|
||||
}
|
||||
}
|
||||
$(document).ready(function () {
|
||||
var url = '${fileTree}';
|
||||
var url = "http://"+'${fileTree}'; //添加http协议方法
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "${baseUrl}directory?urls="+encodeURIComponent(Base64.encode(url)),
|
||||
|
@ -66,6 +80,9 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
window.onload = function () {
|
||||
initWaterMark();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue