mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-10-26 10:49:16 +08:00
1.优化代码结构,抽象预览接口服务
2.新增更多图片预览格式支持
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package cn.keking.service.impl;
|
||||
|
||||
import cn.keking.model.FileAttribute;
|
||||
import cn.keking.model.FileType;
|
||||
import cn.keking.param.ReturnResponse;
|
||||
import cn.keking.service.FilePreview;
|
||||
import cn.keking.utils.FileUtils;
|
||||
import cn.keking.utils.SimTextUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
|
||||
/**
|
||||
* Created by kl on 2018/1/17.
|
||||
* Content :处理文本文件
|
||||
*/
|
||||
@Service
|
||||
public class SimTextFilePreviewImpl implements FilePreview{
|
||||
|
||||
@Autowired
|
||||
SimTextUtil simTextUtil;
|
||||
|
||||
@Autowired
|
||||
FileUtils fileUtils;
|
||||
|
||||
@Override
|
||||
public String filePreviewHandle(String url, Model model){
|
||||
FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
|
||||
String decodedUrl=fileAttribute.getDecodedUrl();
|
||||
String fileName=fileAttribute.getName();
|
||||
ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName);
|
||||
if (0 != response.getCode()) {
|
||||
model.addAttribute("msg", response.getMsg());
|
||||
return "fileNotSupported";
|
||||
}
|
||||
model.addAttribute("ordinaryUrl", response.getMsg());
|
||||
return "txt";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user