2018-01-17 17:51:53 +08:00
|
|
|
package cn.keking.service.impl;
|
|
|
|
|
|
2019-08-22 15:22:05 +08:00
|
|
|
import cn.keking.config.ConfigConstants;
|
2018-01-17 17:51:53 +08:00
|
|
|
import cn.keking.model.FileAttribute;
|
2018-01-19 14:51:18 +08:00
|
|
|
import cn.keking.model.ReturnResponse;
|
2018-01-17 17:51:53 +08:00
|
|
|
import cn.keking.service.FilePreview;
|
|
|
|
|
import cn.keking.utils.DownloadUtils;
|
2020-12-26 19:13:50 +08:00
|
|
|
import cn.keking.service.FileHandlerService;
|
|
|
|
|
import cn.keking.service.CompressFileReader;
|
2018-01-17 17:51:53 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by kl on 2018/1/17.
|
|
|
|
|
* Content :处理压缩包文件
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
2020-05-18 09:46:52 +08:00
|
|
|
public class CompressFilePreviewImpl implements FilePreview {
|
2018-01-17 17:51:53 +08:00
|
|
|
|
2020-12-26 19:13:50 +08:00
|
|
|
private final FileHandlerService fileHandlerService;
|
|
|
|
|
private final CompressFileReader compressFileReader;
|
2020-12-27 14:47:28 +08:00
|
|
|
private final OtherFilePreviewImpl otherFilePreview;
|
2018-01-17 17:51:53 +08:00
|
|
|
|
2020-12-27 14:47:28 +08:00
|
|
|
public CompressFilePreviewImpl(FileHandlerService fileHandlerService, CompressFileReader compressFileReader, OtherFilePreviewImpl otherFilePreview) {
|
2020-12-26 19:13:50 +08:00
|
|
|
this.fileHandlerService = fileHandlerService;
|
|
|
|
|
this.compressFileReader = compressFileReader;
|
2020-12-27 14:47:28 +08:00
|
|
|
this.otherFilePreview = otherFilePreview;
|
2020-05-18 09:46:52 +08:00
|
|
|
}
|
2018-01-17 17:51:53 +08:00
|
|
|
|
|
|
|
|
@Override
|
2019-06-17 14:21:16 +08:00
|
|
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
2018-01-17 17:51:53 +08:00
|
|
|
String fileName=fileAttribute.getName();
|
1,优化URL报错,2,更新OFD组件 3,美化Excel 4,文本方法关闭字节流 5,新增多种类型文件预览 (#419)
1,优化URL报错
2,更新OFD组件
3,美化Excel
4,文本方法关闭字节流
5,新增xmind、eml、epub、"obj", "3ds", "stl", "ply", "off", "3dm", "fbx", "dae", "wrl", "3mf", "ifc","glb","o3dv","gltf","stp","bim","fcstd","step","iges","brep"格式
Co-authored-by: gaoxiongzaq <admin@cxcp.com>
2022-12-28 10:17:06 +08:00
|
|
|
String fileTree;
|
2018-01-17 17:51:53 +08:00
|
|
|
// 判断文件名是否存在(redis缓存读取)
|
2020-12-26 19:13:50 +08:00
|
|
|
if (!StringUtils.hasText(fileHandlerService.getConvertedFile(fileName)) || !ConfigConstants.isCacheEnabled()) {
|
2020-12-27 01:43:50 +08:00
|
|
|
ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
|
2020-12-27 14:06:06 +08:00
|
|
|
if (response.isFailure()) {
|
2020-12-27 14:47:28 +08:00
|
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
|
2018-01-17 17:51:53 +08:00
|
|
|
}
|
|
|
|
|
String filePath = response.getContent();
|
2021-12-17 09:23:32 +08:00
|
|
|
fileTree = compressFileReader.unRar(filePath, fileName);
|
2023-01-11 13:26:18 +08:00
|
|
|
if (fileTree != null && !"null".equals(fileTree)) {
|
|
|
|
|
if (ConfigConstants.isCacheEnabled()) {
|
|
|
|
|
// 加入缓存
|
|
|
|
|
fileHandlerService.addConvertedFile(fileName, fileTree);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-17 17:51:53 +08:00
|
|
|
} else {
|
2020-12-26 19:13:50 +08:00
|
|
|
fileTree = fileHandlerService.getConvertedFile(fileName);
|
2018-01-17 17:51:53 +08:00
|
|
|
}
|
2019-04-18 14:20:37 +08:00
|
|
|
if (fileTree != null && !"null".equals(fileTree)) {
|
2018-01-17 17:51:53 +08:00
|
|
|
model.addAttribute("fileTree", fileTree);
|
2020-12-27 15:14:32 +08:00
|
|
|
return COMPRESS_FILE_PREVIEW_PAGE;
|
2018-01-17 17:51:53 +08:00
|
|
|
} else {
|
2021-12-17 09:23:32 +08:00
|
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件类型不受支持");
|
2018-01-17 17:51:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|