Skip to content

Commit

Permalink
!248 1.修复压缩包 二级目录无法解压问题 修改压缩包生成PDF路径 2.修复PDF 带密码缓存问题 新增PDF带密码缓存方法 use…
Browse files Browse the repository at this point in the history
…rToken 3.精简OFFICE 转换代码 4.精简TIF转换代码 新增TIF转换图片缓存 修复tif错误文件不自动释放内存 等待其他修复 5.修复下载方法错 特殊符号下载错误

Merge pull request !248 from 高雄/qttiaozheng
  • Loading branch information
klboke authored and gitee-org committed Dec 18, 2023
2 parents 904b949 + 9f9790d commit 13dfca0
Show file tree
Hide file tree
Showing 16 changed files with 554 additions and 387 deletions.
41 changes: 38 additions & 3 deletions server/src/main/java/cn/keking/model/FileAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ public class FileAttribute {
private String url;
private String fileKey;
private String filePassword;
private String userToken;
private boolean userToken;
private String officePreviewType = ConfigConstants.getOfficePreviewType();
private String tifPreviewType;
private Boolean skipDownLoad = false;
private Boolean forceUpdatedCache = false;
private String cacheName;
private String outFilePath;
private String fileNameFilePath;
private String cacheListName;
private boolean isHtml;

/**
* 代理请求到文件服务器的认证请求头,格式如下:
Expand Down Expand Up @@ -61,11 +66,11 @@ public void setFilePassword(String filePassword) {
this.filePassword = filePassword;
}

public String getUserToken() {
public boolean getUserToken() {
return userToken;
}

public void setUserToken(String userToken) {
public void setUserToken(boolean userToken) {
this.userToken = userToken;
}

Expand Down Expand Up @@ -96,7 +101,37 @@ public void setSuffix(String suffix) {
public String getName() {
return name;
}
public String getcacheName() {
return cacheName;
}
public String getcacheListName() {
return cacheListName;
}
public String getoutFilePath() {
return outFilePath;
}
public String getfileNameFilePath() {
return fileNameFilePath;
}
public boolean getisHtml() {
return isHtml;
}

public void setcacheName(String cacheName) {
this.cacheName = cacheName;
}
public void setcacheListName(String cacheListName) {
this.cacheListName = cacheListName;
}
public void setoutFilePath(String outFilePath) {
this.outFilePath = outFilePath;
}
public void setfileNameFilePath(String fileNameFilePath) {
this.fileNameFilePath = fileNameFilePath;
}
public void setisHtml(boolean isHtml) {
this.isHtml = isHtml;
}
public void setName(String name) {
this.name = name;
}
Expand Down
7 changes: 4 additions & 3 deletions server/src/main/java/cn/keking/model/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum FileType {
CODE("codeFilePreviewImpl"),
OTHER("otherFilePreviewImpl"),
MEDIA("mediaFilePreviewImpl"),
MEDIACONVERT("mediaFilePreviewImpl"),
MARKDOWN("markdownFilePreviewImpl"),
XML("xmlFilePreviewImpl"),
CAD("cadFilePreviewImpl"),
Expand Down Expand Up @@ -50,7 +51,7 @@ public enum FileType {
private static final String[] SSIM_TEXT_TYPES = ConfigConstants.getSimText();
private static final String[] CODES = {"java", "c", "php", "go", "python", "py", "js", "html", "ftl", "css", "lua", "sh", "rb", "yaml", "yml", "json", "h", "cpp", "cs", "aspx", "jsp", "sql"};
private static final String[] MEDIA_TYPES = ConfigConstants.getMedia();
public static final String[] MEDIA_TYPES_CONVERT = ConfigConstants.getConvertMedias();
public static final String[] MEDIACONVERT_TYPES_CONVERT = ConfigConstants.getConvertMedias();
private static final Map<String, FileType> FILE_TYPE_MAPPER = new HashMap<>();

static {
Expand All @@ -69,8 +70,8 @@ public enum FileType {
for (String media : MEDIA_TYPES) {
FILE_TYPE_MAPPER.put(media, FileType.MEDIA);
}
for (String media : MEDIA_TYPES_CONVERT) {
FILE_TYPE_MAPPER.put(media, FileType.MEDIA);
for (String MEDIACONVERT : MEDIACONVERT_TYPES_CONVERT) {
FILE_TYPE_MAPPER.put( MEDIACONVERT, FileType. MEDIACONVERT);
}
for (String tif : TIFF_TYPES) {
FILE_TYPE_MAPPER.put(tif, FileType.TIFF);
Expand Down
26 changes: 16 additions & 10 deletions server/src/main/java/cn/keking/service/CompressFileReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.keking.service;

import cn.keking.config.ConfigConstants;
import cn.keking.model.FileType;
import cn.keking.utils.RarUtils;
import cn.keking.web.filter.BaseUrlFilter;
Expand All @@ -12,6 +13,7 @@
import net.sf.sevenzipjbinding.simple.ISimpleInArchiveItem;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
Expand All @@ -25,45 +27,49 @@
@Component
public class CompressFileReader {
private final FileHandlerService fileHandlerService;
private static final String fileDir = ConfigConstants.getFileDir();
public CompressFileReader(FileHandlerService fileHandlerService) {
this.fileHandlerService = fileHandlerService;
}
public String unRar(String paths, String passWord, String fileName) throws Exception {
public String unRar(String filePath, String filePassword, String fileName, String fileKey) throws Exception {
List<String> imgUrls = new ArrayList<>();
String baseUrl = BaseUrlFilter.getBaseUrl();
String archiveFileName = fileHandlerService.getFileNameFromPath(paths);
String folderName = filePath.replace(fileDir, ""); //修复压缩包 多重目录获取路径错误
if (!ObjectUtils.isEmpty(fileKey)) { //压缩包文件 直接赋予路径 不予下载
folderName = "_decompression"+folderName;
}
RandomAccessFile randomAccessFile = null;
IInArchive inArchive = null;
try {
randomAccessFile = new RandomAccessFile(paths, "r");
randomAccessFile = new RandomAccessFile(filePath, "r");
inArchive = SevenZip.openInArchive(null, new RandomAccessFileInStream(randomAccessFile));
String folderName = paths.substring(paths.lastIndexOf(File.separator) + 1);
String extractPath = paths.substring(0, paths.lastIndexOf(folderName));
ISimpleInArchive simpleInArchive = inArchive.getSimpleInterface();
final String[] str = {null};
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
if (!item.isFolder()) {
ExtractOperationResult result;
String finalFolderName = folderName;
result = item.extractSlow(data -> {
try {
str[0] = RarUtils.getUtf8String(item.getPath());
str[0] = RarUtils.getUtf8String(item.getPath());
if (RarUtils.isMessyCode(str[0])){
str[0] = new String(item.getPath().getBytes(StandardCharsets.ISO_8859_1), "gbk");
}
str[0] = str[0].replace("\\", File.separator); //Linux 下路径错误
String str1 = str[0].substring(0, str[0].lastIndexOf(File.separator)+ 1);
File file = new File(extractPath, folderName + "_" + File.separator + str1);
File file = new File(fileDir, finalFolderName + "_" + File.separator + str1);
if (!file.exists()) {
file.mkdirs();
}
OutputStream out = new FileOutputStream( extractPath+ folderName + "_" + File.separator + str[0], true);
OutputStream out = new FileOutputStream( fileDir+ finalFolderName + "_" + File.separator + str[0], true);
IOUtils.write(data, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
return Integer.parseInt(null);
}
return data.length;
}, passWord);
}, filePassword);
if (result == ExtractOperationResult.OK) {
FileType type = FileType.typeFromUrl(str[0]);
if (type.equals(FileType.PICTURE)) {
Expand All @@ -75,7 +81,7 @@ public String unRar(String paths, String passWord, String fileName) throws Excep
}
}
}
return archiveFileName + "_";
return folderName + "_";
} catch (Exception e) {
throw new Exception(e);
} finally {
Expand Down
Loading

0 comments on commit 13dfca0

Please sign in to comment.