mirror of
https://github.com/kekingcn/kkFileView.git
synced 2026-04-19 18:28:39 +00:00
55 lines
2.2 KiB
Java
55 lines
2.2 KiB
Java
package cn.keking.service.impl;
|
|
|
|
import cn.keking.config.ConfigConstants;
|
|
import cn.keking.model.FileAttribute;
|
|
import cn.keking.model.ReturnResponse;
|
|
import cn.keking.service.FilePreview;
|
|
import cn.keking.utils.DownloadUtils;
|
|
import cn.keking.service.FileHandlerService;
|
|
import cn.keking.service.CompressFileReader;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
/**
|
|
* Created by kl on 2018/1/17.
|
|
* Content :处理压缩包文件
|
|
*/
|
|
@Service
|
|
public class CompressFilePreviewImpl implements FilePreview {
|
|
|
|
private final FileHandlerService fileHandlerService;
|
|
private final CompressFileReader compressFileReader;
|
|
private final OtherFilePreviewImpl otherFilePreview;
|
|
|
|
public CompressFilePreviewImpl(FileHandlerService fileHandlerService, CompressFileReader compressFileReader, OtherFilePreviewImpl otherFilePreview) {
|
|
this.fileHandlerService = fileHandlerService;
|
|
this.compressFileReader = compressFileReader;
|
|
this.otherFilePreview = otherFilePreview;
|
|
}
|
|
|
|
@Override
|
|
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
|
String fileName=fileAttribute.getName();
|
|
String suffix=fileAttribute.getSuffix();
|
|
String fileTree = null;
|
|
// 判断文件名是否存在(redis缓存读取)
|
|
if (!StringUtils.hasText(fileHandlerService.getConvertedFile(fileName)) || !ConfigConstants.isCacheEnabled()) {
|
|
ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, fileName);
|
|
if (response.isFailure()) {
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
|
|
}
|
|
String filePath = response.getContent();
|
|
fileTree = compressFileReader.unRar(filePath, fileName);
|
|
} else {
|
|
fileTree = fileHandlerService.getConvertedFile(fileName);
|
|
}
|
|
if (fileTree != null && !"null".equals(fileTree)) {
|
|
model.addAttribute("fileTree", fileTree);
|
|
return COMPRESS_FILE_PREVIEW_PAGE;
|
|
} else {
|
|
return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件类型不受支持");
|
|
}
|
|
}
|
|
}
|