From 602e80ee9e7ead0e228c896d7a752fa411f709ec Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Sun, 27 Dec 2020 15:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8B=AC=E7=AB=8Bflv=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/keking/model/FileType.java | 8 ++++-- .../java/cn/keking/service/FilePreview.java | 11 ++++++++ .../service/impl/CadFilePreviewImpl.java | 2 +- .../service/impl/CompressFilePreviewImpl.java | 2 +- .../service/impl/FlvFilePreviewImpl.java | 27 +++++++++++++++++++ .../service/impl/MediaFilePreviewImpl.java | 6 +---- .../service/impl/OfficeFilePreviewImpl.java | 6 ++--- .../service/impl/OtherFilePreviewImpl.java | 1 - .../service/impl/PdfFilePreviewImpl.java | 6 ++--- .../service/impl/PictureFilePreviewImpl.java | 2 +- .../service/impl/SimTextFilePreviewImpl.java | 2 +- 11 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 server/src/main/java/cn/keking/service/impl/FlvFilePreviewImpl.java diff --git a/server/src/main/java/cn/keking/model/FileType.java b/server/src/main/java/cn/keking/model/FileType.java index 08a71872..a07d8e58 100644 --- a/server/src/main/java/cn/keking/model/FileType.java +++ b/server/src/main/java/cn/keking/model/FileType.java @@ -10,6 +10,7 @@ import java.util.Map; * Content :文件类型,文本,office,压缩包等等 */ public enum FileType { + picture("pictureFilePreviewImpl"), compress("compressFilePreviewImpl"), office("officeFilePreviewImpl"), @@ -19,12 +20,13 @@ public enum FileType { media("mediaFilePreviewImpl"), markdown("markdownFilePreviewImpl"), xml("xmlFilePreviewImpl"), + flv("flvFilePreviewImpl"), cad("cadFilePreviewImpl"); private static final String[] OFFICE_TYPES = {"docx", "doc", "xls", "xlsx", "ppt", "pptx"}; private static final String[] PICTURE_TYPES = {"jpg", "jpeg", "png", "gif", "bmp", "ico", "RAW"}; private static final String[] ARCHIVE_TYPES = {"rar", "zip", "jar", "7-zip", "tar", "gzip", "7z"}; - private static final String[] SIMTEXT_TYPES = ConfigConstants.getSimText(); + private static final String[] SSIM_TEXT_TYPES = ConfigConstants.getSimText(); private static final String[] MEDIA_TYPES = ConfigConstants.getMedia(); private static final Map FILE_TYPE_MAPPER = new HashMap<>(); @@ -38,7 +40,7 @@ public enum FileType { for (String archive : ARCHIVE_TYPES) { FILE_TYPE_MAPPER.put(archive, FileType.compress); } - for (String text : SIMTEXT_TYPES) { + for (String text : SSIM_TEXT_TYPES) { FILE_TYPE_MAPPER.put(text, FileType.simText); } for (String media : MEDIA_TYPES) { @@ -48,6 +50,8 @@ public enum FileType { FILE_TYPE_MAPPER.put("xml", FileType.xml); FILE_TYPE_MAPPER.put("pdf", FileType.pdf); FILE_TYPE_MAPPER.put("dwg", FileType.cad); + FILE_TYPE_MAPPER.put("flv", FileType.flv); + } private static FileType to(String fileType){ diff --git a/server/src/main/java/cn/keking/service/FilePreview.java b/server/src/main/java/cn/keking/service/FilePreview.java index 229fcc80..a795992e 100644 --- a/server/src/main/java/cn/keking/service/FilePreview.java +++ b/server/src/main/java/cn/keking/service/FilePreview.java @@ -8,5 +8,16 @@ import org.springframework.ui.Model; * Content : */ public interface FilePreview { + + String FLV_FILE_PREVIEW_PAGE = "flv"; + String PDF_FILE_PREVIEW_PAGE = "pdf"; + String COMPRESS_FILE_PREVIEW_PAGE = "compress"; + String MEDIA_FILE_PREVIEW_PAGE = "media"; + String PICTURE_FILE_PREVIEW_PAGE = "picture"; + String OFFICE_PICTURE_FILE_PREVIEW_PAGE = "officePicture"; + String TXT_FILE_PREVIEW_PAGE = "txt"; + String EXEL_FILE_PREVIEW_PAGE = "html"; + String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported"; + String filePreviewHandle(String url, Model model, FileAttribute fileAttribute); } diff --git a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java index f9b9e174..72b1d80e 100644 --- a/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java @@ -63,7 +63,7 @@ public class CadFilePreviewImpl implements FilePreview { return getPreviewType(model, fileAttribute, officePreviewType, baseUrl, pdfName, outFilePath, fileHandlerService, OFFICE_PREVIEW_TYPE_IMAGE,otherFilePreview); } model.addAttribute("pdfUrl", pdfName); - return "pdf"; + return PDF_FILE_PREVIEW_PAGE; } diff --git a/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java index b898d0a2..ed2d2ae9 100644 --- a/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java @@ -55,7 +55,7 @@ public class CompressFilePreviewImpl implements FilePreview { } if (fileTree != null && !"null".equals(fileTree)) { model.addAttribute("fileTree", fileTree); - return "compress"; + return COMPRESS_FILE_PREVIEW_PAGE; } else { return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件类型不受支持,尝试在压缩的时候选择RAR4格式"); } diff --git a/server/src/main/java/cn/keking/service/impl/FlvFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/FlvFilePreviewImpl.java new file mode 100644 index 00000000..1e1950d8 --- /dev/null +++ b/server/src/main/java/cn/keking/service/impl/FlvFilePreviewImpl.java @@ -0,0 +1,27 @@ +package cn.keking.service.impl; + +import cn.keking.model.FileAttribute; +import cn.keking.service.FilePreview; +import org.springframework.stereotype.Service; +import org.springframework.ui.Model; + +/** + * @author : kl + * create : 2020-12-27 2:50 下午 + * flv文件预览处理实现 + **/ +@Service +public class FlvFilePreviewImpl implements FilePreview { + + private final MediaFilePreviewImpl mediaFilePreview; + + public FlvFilePreviewImpl(MediaFilePreviewImpl mediaFilePreview) { + this.mediaFilePreview = mediaFilePreview; + } + + @Override + public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { + mediaFilePreview.filePreviewHandle(url,model,fileAttribute); + return FLV_FILE_PREVIEW_PAGE; + } +} diff --git a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java index 39ea3a67..eb1ec1ad 100644 --- a/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java @@ -40,11 +40,7 @@ public class MediaFilePreviewImpl implements FilePreview { model.addAttribute("mediaUrl", url); } model.addAttribute("mediaUrl", url); - String suffix = fileAttribute.getSuffix(); - if ("flv".equalsIgnoreCase(suffix)) { - return "flv"; - } - return "media"; + return MEDIA_FILE_PREVIEW_PAGE; } diff --git a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java index 221b52ad..dc6977f5 100644 --- a/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java @@ -69,7 +69,7 @@ public class OfficeFilePreviewImpl implements FilePreview { return getPreviewType(model, fileAttribute, officePreviewType, baseUrl, pdfName, outFilePath, fileHandlerService, OFFICE_PREVIEW_TYPE_IMAGE, otherFilePreview); } model.addAttribute("pdfUrl", pdfName); - return isHtml ? "html" : "pdf"; + return isHtml ? EXEL_FILE_PREVIEW_PAGE : PDF_FILE_PREVIEW_PAGE; } static String getPreviewType(Model model, FileAttribute fileAttribute, String officePreviewType, String baseUrl, String pdfName, String outFilePath, FileHandlerService fileHandlerService, String officePreviewTypeImage, OtherFilePreviewImpl otherFilePreview) { @@ -80,9 +80,9 @@ public class OfficeFilePreviewImpl implements FilePreview { model.addAttribute("imgurls", imageUrls); model.addAttribute("currentUrl", imageUrls.get(0)); if (officePreviewTypeImage.equals(officePreviewType)) { - return "officePicture"; + return OFFICE_PICTURE_FILE_PREVIEW_PAGE; } else { - return "picture"; + return PICTURE_FILE_PREVIEW_PAGE; } } } diff --git a/server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java index fbe22443..48a17ff8 100644 --- a/server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java @@ -12,7 +12,6 @@ import org.springframework.ui.Model; @Service public class OtherFilePreviewImpl implements FilePreview { - public static final String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported"; @Override public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { diff --git a/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java index 3f24b54c..e803b785 100644 --- a/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java @@ -55,9 +55,9 @@ public class PdfFilePreviewImpl implements FilePreview { model.addAttribute("imgurls", imageUrls); model.addAttribute("currentUrl", imageUrls.get(0)); if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType)) { - return "officePicture"; + return OFFICE_PICTURE_FILE_PREVIEW_PAGE; } else { - return "picture"; + return PICTURE_FILE_PREVIEW_PAGE; } } else { // 不是http开头,浏览器不能直接访问,需下载到本地 @@ -79,6 +79,6 @@ public class PdfFilePreviewImpl implements FilePreview { model.addAttribute("pdfUrl", url); } } - return "pdf"; + return PDF_FILE_PREVIEW_PAGE; } } diff --git a/server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java index 68af1771..d8361f59 100644 --- a/server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java @@ -51,6 +51,6 @@ public class PictureFilePreviewImpl implements FilePreview { model.addAttribute("imgurls", imgUrls); model.addAttribute("currentUrl", url); } - return "picture"; + return PICTURE_FILE_PREVIEW_PAGE; } } diff --git a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java index 1559c63c..06cdb896 100644 --- a/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java +++ b/server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java @@ -46,7 +46,7 @@ public class SimTextFilePreviewImpl implements FilePreview { if (!model.containsAttribute(TEXT_TYPE)) { model.addAttribute(TEXT_TYPE, DEFAULT_TEXT_TYPE); } - return "txt"; + return TXT_FILE_PREVIEW_PAGE; } }