mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-26 19:13:52 +08:00
预览逻辑重构
This commit is contained in:
@@ -67,7 +67,7 @@ public class FileConvertQueueTask {
|
||||
try {
|
||||
url = cacheService.takeQueueTask();
|
||||
if(url != null){
|
||||
FileAttribute fileAttribute = fileUtils.getFileAttribute(url);
|
||||
FileAttribute fileAttribute = fileUtils.getFileAttribute(url,null);
|
||||
FileType fileType = fileAttribute.getType();
|
||||
logger.info("正在处理预览转换任务,url:{},预览类型:{}", url, fileType);
|
||||
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.keking.service;
|
||||
|
||||
import cn.keking.config.ConfigConstants;
|
||||
import cn.keking.model.FileAttribute;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
@@ -8,5 +9,9 @@ import org.springframework.ui.Model;
|
||||
* Content :
|
||||
*/
|
||||
public interface FilePreview {
|
||||
|
||||
String TEXT_TYPE = "textType";
|
||||
String DEFAULT_TEXT_TYPE = "simText";
|
||||
|
||||
String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class MarkdownFilePreviewImpl implements FilePreview {
|
||||
|
||||
@Override
|
||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||
model.addAttribute("textType","markdown");
|
||||
model.addAttribute(TEXT_TYPE,"markdown");
|
||||
return simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PdfFilePreviewImpl implements FilePreview {
|
||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||
String suffix=fileAttribute.getSuffix();
|
||||
String fileName=fileAttribute.getName();
|
||||
String officePreviewType = model.asMap().get("officePreviewType") == null ? ConfigConstants.getOfficePreviewType() : model.asMap().get("officePreviewType").toString();
|
||||
String officePreviewType = fileAttribute.getOfficePreviewType();
|
||||
String baseUrl = BaseUrlFilter.getBaseUrl();
|
||||
String pdfName = fileName.substring(0, fileName.lastIndexOf(".") + 1) + "pdf";
|
||||
String outFilePath = FILE_DIR + pdfName;
|
||||
|
||||
@@ -24,6 +24,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
|
||||
|
||||
private final DownloadUtils downloadUtils;
|
||||
|
||||
|
||||
public SimTextFilePreviewImpl(DownloadUtils downloadUtils) {
|
||||
this.downloadUtils = downloadUtils;
|
||||
}
|
||||
@@ -46,6 +47,9 @@ public class SimTextFilePreviewImpl implements FilePreview {
|
||||
model.addAttribute("fileType", fileAttribute.getSuffix());
|
||||
return "fileNotSupported";
|
||||
}
|
||||
if (!model.containsAttribute(TEXT_TYPE)) {
|
||||
model.addAttribute(TEXT_TYPE, DEFAULT_TEXT_TYPE);
|
||||
}
|
||||
return "txt";
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class XmlFilePreviewImpl implements FilePreview {
|
||||
|
||||
@Override
|
||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||
model.addAttribute("textType","xml");
|
||||
model.addAttribute(TEXT_TYPE,"xml");
|
||||
return simTextFilePreview.filePreviewHandle(url, model, fileAttribute);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user