Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a2eef41ec7 | |||
| 60da610d1f | |||
| 08415aa5ca |
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,7 +17,6 @@ target/
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
@ -29,4 +28,3 @@ nbdist/
|
||||
|
||||
server/src/main/cache/
|
||||
server/src/main/file/
|
||||
server/src/main/log
|
||||
@ -15,7 +15,7 @@ public class OtherFilePreviewImpl implements FilePreview {
|
||||
|
||||
@Override
|
||||
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
|
||||
return this.notSupportedFile(model,fileAttribute,"系统还不支持该格式文件的在线预览");
|
||||
return this.notSupportedFile(model, fileAttribute, "系统还不支持该格式文件的在线预览");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,8 +24,28 @@ public class OtherFilePreviewImpl implements FilePreview {
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, FileAttribute fileAttribute, String errMsg) {
|
||||
model.addAttribute("fileType", fileAttribute.getSuffix());
|
||||
return this.notSupportedFile(model, fileAttribute.getSuffix(), errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的预览失败,导向到不支持的文件响应页面
|
||||
*
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, String errMsg) {
|
||||
return this.notSupportedFile(model, "未知", errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的预览失败,导向到不支持的文件响应页面
|
||||
*
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, String fileType, String errMsg) {
|
||||
model.addAttribute("fileType", fileType);
|
||||
model.addAttribute("msg", errMsg);
|
||||
return NOT_SUPPORTED_FILE_PAGE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.keking.service.FilePreview;
|
||||
import cn.keking.service.FilePreviewFactory;
|
||||
|
||||
import cn.keking.service.cache.CacheService;
|
||||
import cn.keking.service.impl.OtherFilePreviewImpl;
|
||||
import cn.keking.utils.DownloadUtils;
|
||||
import cn.keking.service.FileHandlerService;
|
||||
import org.slf4j.Logger;
|
||||
@ -31,21 +32,30 @@ import static cn.keking.service.FilePreview.PICTURE_FILE_PREVIEW_PAGE;
|
||||
@Controller
|
||||
public class OnlinePreviewController {
|
||||
|
||||
public static final String BASE64_DECODE_ERROR_MSG = "Base64解码失败,请检查你的 %s 是否采用 Base64 + urlEncode 双重编码了!";
|
||||
private final Logger logger = LoggerFactory.getLogger(OnlinePreviewController.class);
|
||||
|
||||
private final FilePreviewFactory previewFactory;
|
||||
private final CacheService cacheService;
|
||||
private final FileHandlerService fileHandlerService;
|
||||
private final OtherFilePreviewImpl otherFilePreview;
|
||||
|
||||
public OnlinePreviewController(FilePreviewFactory filePreviewFactory, FileHandlerService fileHandlerService, CacheService cacheService) {
|
||||
public OnlinePreviewController(FilePreviewFactory filePreviewFactory, FileHandlerService fileHandlerService, CacheService cacheService, OtherFilePreviewImpl otherFilePreview) {
|
||||
this.previewFactory = filePreviewFactory;
|
||||
this.fileHandlerService = fileHandlerService;
|
||||
this.cacheService = cacheService;
|
||||
this.otherFilePreview = otherFilePreview;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/onlinePreview")
|
||||
public String onlinePreview(String url, Model model, HttpServletRequest req) {
|
||||
String fileUrl = new String(Base64Utils.decodeFromString(url));
|
||||
String fileUrl;
|
||||
try {
|
||||
fileUrl = new String(Base64Utils.decodeFromString(url));
|
||||
} catch (Exception ex) {
|
||||
String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "url");
|
||||
return otherFilePreview.notSupportedFile(model, errorMsg);
|
||||
}
|
||||
FileAttribute fileAttribute = fileHandlerService.getFileAttribute(fileUrl, req);
|
||||
FilePreview filePreview = previewFactory.get(fileAttribute);
|
||||
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
||||
@ -54,18 +64,24 @@ public class OnlinePreviewController {
|
||||
|
||||
@RequestMapping(value = "/picturesPreview")
|
||||
public String picturesPreview(String urls, Model model, HttpServletRequest req) throws UnsupportedEncodingException {
|
||||
String fileUrls = new String(Base64Utils.decodeFromString(urls));
|
||||
String fileUrls;
|
||||
try {
|
||||
fileUrls = new String(Base64Utils.decodeFromString(urls));
|
||||
} catch (Exception ex) {
|
||||
String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "urls");
|
||||
return otherFilePreview.notSupportedFile(model, errorMsg);
|
||||
}
|
||||
logger.info("预览文件url:{},urls:{}", fileUrls, urls);
|
||||
// 抽取文件并返回文件列表
|
||||
String[] imgs = fileUrls.split("\\|");
|
||||
List<String> imgUrls = Arrays.asList(imgs);
|
||||
String[] images = fileUrls.split("\\|");
|
||||
List<String> imgUrls = Arrays.asList(images);
|
||||
model.addAttribute("imgUrls", imgUrls);
|
||||
|
||||
String currentUrl = req.getParameter("currentUrl");
|
||||
if(StringUtils.hasText(currentUrl)){
|
||||
if (StringUtils.hasText(currentUrl)) {
|
||||
String decodedCurrentUrl = new String(Base64Utils.decodeFromString(currentUrl));
|
||||
model.addAttribute("currentUrl", decodedCurrentUrl);
|
||||
}else {
|
||||
} else {
|
||||
model.addAttribute("currentUrl", imgUrls.get(0));
|
||||
}
|
||||
return PICTURE_FILE_PREVIEW_PAGE;
|
||||
|
||||
7
server/src/main/log/README.txt
Normal file
7
server/src/main/log/README.txt
Normal file
@ -0,0 +1,7 @@
|
||||
README.txt
|
||||
log目录是用来存放kkFileView.log的,预览服务的运行情况最终都会反映到这个日志文件里,
|
||||
可以提供给开发、运维排查系统问题。如果通过kkFileView.log还无法定位问题所在,请你在寻求
|
||||
kk官方支持时,QQ群一 613025121、QQ群二 484680571。将此日志文件一并携带,并按照这个
|
||||
格式重命名日志文件 kkFileView-QQ昵称-时间日期.log。如:kkFileView-kl博主-2020-12-27.log 。
|
||||
所有收集的日志文件我们都会存档,供所有的kk用户作为排查案例使用,所以在你提供日志前,请
|
||||
先自行处理日志文件里的业务敏感内容。
|
||||
25473
server/src/main/resources/static/pdfjs/build/pdf.js
Normal file
25473
server/src/main/resources/static/pdfjs/build/pdf.js
Normal file
File diff suppressed because it is too large
Load Diff
1
server/src/main/resources/static/pdfjs/build/pdf.js.map
Normal file
1
server/src/main/resources/static/pdfjs/build/pdf.js.map
Normal file
File diff suppressed because one or more lines are too long
57878
server/src/main/resources/static/pdfjs/build/pdf.worker.js
vendored
Normal file
57878
server/src/main/resources/static/pdfjs/build/pdf.worker.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
server/src/main/resources/static/pdfjs/build/pdf.worker.js.map
vendored
Normal file
1
server/src/main/resources/static/pdfjs/build/pdf.worker.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user