|
|
@@ -55,37 +55,51 @@ public class PreviewController {
|
|
|
vo.setEdit(false);
|
|
|
log.info("==> 查看文档 vo: {}", vo);
|
|
|
Pair<Document, DocumentEditParam> pair = docInfo(vo);
|
|
|
- model.addAttribute("name", vo.getName());
|
|
|
|
|
|
+ String filename = vo.getName();
|
|
|
String bucketName = pair.getKey().getStorage();
|
|
|
- if (!ossTemplate.exist(bucketName, vo.getName())) {
|
|
|
+ String downloadUrl = "/download?name=" + filename + "&bucket=" + bucketName;
|
|
|
+
|
|
|
+ model.addAttribute("name", filename);
|
|
|
+ model.addAttribute("downloadUrl", downloadUrl);
|
|
|
+ if (!ossTemplate.exist(bucketName, filename)) {
|
|
|
return "/notFound";
|
|
|
}
|
|
|
|
|
|
- Optional<MediaType> opt = MediaTypeFactory.getMediaType(vo.getName());
|
|
|
- if (opt.isPresent()) {
|
|
|
- MediaType mediaType = opt.get();
|
|
|
- //图片
|
|
|
- if (mediaType.getType().equals("image")) {
|
|
|
- model.addAttribute("src", "/download?name=" + vo.getName() + "&bucket=" + bucketName);
|
|
|
- return "/viewerImg";
|
|
|
- }
|
|
|
- //文本
|
|
|
- if (mediaType.getType().equals("text")) {
|
|
|
- S3ObjectInputStream inputStream = ossTemplate.getObject(bucketName, vo.getName()).getObjectContent();
|
|
|
- model.addAttribute("content", IoUtil.read(inputStream, StandardCharsets.UTF_8));
|
|
|
- return "/viewerTxt";
|
|
|
- }
|
|
|
+ Optional<MediaType> opt = MediaTypeFactory.getMediaType(filename);
|
|
|
+ if (!opt.isPresent()) {
|
|
|
+ return "/cannotPreview";
|
|
|
}
|
|
|
+ MediaType mediaType = opt.get();
|
|
|
|
|
|
- model.addAttribute("document", pair.getKey());
|
|
|
- model.addAttribute("documentEditParam", pair.getValue());
|
|
|
+ //图片
|
|
|
+ if (mediaType.getType().equals("image")) {
|
|
|
+ return "/viewerImg";
|
|
|
+ }
|
|
|
|
|
|
- String suffix = FileNameUtil.getSuffix(vo.getName());
|
|
|
- if (suffix.equalsIgnoreCase("xls") || suffix.equalsIgnoreCase("xlsx")) {
|
|
|
+ //文本
|
|
|
+ if (mediaType.getType().equals("text")) {
|
|
|
+ S3ObjectInputStream inputStream = ossTemplate.getObject(bucketName, filename).getObjectContent();
|
|
|
+ model.addAttribute("content", IoUtil.read(inputStream, StandardCharsets.UTF_8));
|
|
|
+ return "/viewerTxt";
|
|
|
+ }
|
|
|
+
|
|
|
+ //表格
|
|
|
+ if (DocumentConstants.EXCEL_MEDIA_TYPES.contains(mediaType)) {
|
|
|
+ model.addAttribute("document", pair.getKey());
|
|
|
+ model.addAttribute("documentEditParam", pair.getValue());
|
|
|
return "/viewerExcel";
|
|
|
}
|
|
|
- return "/viewer";
|
|
|
+
|
|
|
+ //文档
|
|
|
+ if (DocumentConstants.DOC_MEDIA_TYPES.contains(mediaType)) {
|
|
|
+ model.addAttribute("document", pair.getKey());
|
|
|
+ model.addAttribute("documentEditParam", pair.getValue());
|
|
|
+ return "/viewer";
|
|
|
+ }
|
|
|
+
|
|
|
+ //其他文件无法预览
|
|
|
+ return "/cannotPreview";
|
|
|
}
|
|
|
|
|
|
@GetMapping("/edit")
|