修复压缩获取路径错误,图片合集路径错误,水印问题等BUG

This commit is contained in:
gaoxiongzaq
2024-05-27 14:21:11 +08:00
parent 0a4ae41b0c
commit 48ac926289
6 changed files with 39 additions and 25 deletions

View File

@@ -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 {
}
}
}

View File

@@ -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();

View File

@@ -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)) {