Browse Source

独立flv文件预览实现

flv
chenkailing 4 years ago
parent
commit
d8a49a2862
  1. 8
      server/src/main/java/cn/keking/model/FileType.java
  2. 11
      server/src/main/java/cn/keking/service/FilePreview.java
  3. 2
      server/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java
  4. 2
      server/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java
  5. 27
      server/src/main/java/cn/keking/service/impl/FlvFilePreviewImpl.java
  6. 6
      server/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java
  7. 6
      server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
  8. 1
      server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java
  9. 6
      server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
  10. 2
      server/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java
  11. 2
      server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java

8
server/src/main/java/cn/keking/model/FileType.java

@ -10,6 +10,7 @@ import java.util.Map;
* Content :文件类型文本office压缩包等等 * Content :文件类型文本office压缩包等等
*/ */
public enum FileType { public enum FileType {
picture("pictureFilePreviewImpl"), picture("pictureFilePreviewImpl"),
compress("compressFilePreviewImpl"), compress("compressFilePreviewImpl"),
office("officeFilePreviewImpl"), office("officeFilePreviewImpl"),
@ -19,12 +20,13 @@ public enum FileType {
media("mediaFilePreviewImpl"), media("mediaFilePreviewImpl"),
markdown("markdownFilePreviewImpl"), markdown("markdownFilePreviewImpl"),
xml("xmlFilePreviewImpl"), xml("xmlFilePreviewImpl"),
flv("flvFilePreviewImpl"),
cad("cadFilePreviewImpl"); cad("cadFilePreviewImpl");
private static final String[] OFFICE_TYPES = {"docx", "doc", "xls", "xlsx", "ppt", "pptx"}; 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[] 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[] 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 String[] MEDIA_TYPES = ConfigConstants.getMedia();
private static final Map<String, FileType> FILE_TYPE_MAPPER = new HashMap<>(); private static final Map<String, FileType> FILE_TYPE_MAPPER = new HashMap<>();
@ -38,7 +40,7 @@ public enum FileType {
for (String archive : ARCHIVE_TYPES) { for (String archive : ARCHIVE_TYPES) {
FILE_TYPE_MAPPER.put(archive, FileType.compress); 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); FILE_TYPE_MAPPER.put(text, FileType.simText);
} }
for (String media : MEDIA_TYPES) { for (String media : MEDIA_TYPES) {
@ -48,6 +50,8 @@ public enum FileType {
FILE_TYPE_MAPPER.put("xml", FileType.xml); FILE_TYPE_MAPPER.put("xml", FileType.xml);
FILE_TYPE_MAPPER.put("pdf", FileType.pdf); FILE_TYPE_MAPPER.put("pdf", FileType.pdf);
FILE_TYPE_MAPPER.put("dwg", FileType.cad); FILE_TYPE_MAPPER.put("dwg", FileType.cad);
FILE_TYPE_MAPPER.put("flv", FileType.flv);
} }
private static FileType to(String fileType){ private static FileType to(String fileType){

11
server/src/main/java/cn/keking/service/FilePreview.java

@ -8,5 +8,16 @@ import org.springframework.ui.Model;
* Content : * Content :
*/ */
public interface FilePreview { 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); String filePreviewHandle(String url, Model model, FileAttribute fileAttribute);
} }

2
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); return getPreviewType(model, fileAttribute, officePreviewType, baseUrl, pdfName, outFilePath, fileHandlerService, OFFICE_PREVIEW_TYPE_IMAGE,otherFilePreview);
} }
model.addAttribute("pdfUrl", pdfName); model.addAttribute("pdfUrl", pdfName);
return "pdf"; return PDF_FILE_PREVIEW_PAGE;
} }

2
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)) { if (fileTree != null && !"null".equals(fileTree)) {
model.addAttribute("fileTree", fileTree); model.addAttribute("fileTree", fileTree);
return "compress"; return COMPRESS_FILE_PREVIEW_PAGE;
} else { } else {
return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件类型不受支持,尝试在压缩的时候选择RAR4格式"); return otherFilePreview.notSupportedFile(model, fileAttribute, "压缩文件类型不受支持,尝试在压缩的时候选择RAR4格式");
} }

27
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;
}
}

6
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);
} }
model.addAttribute("mediaUrl", url); model.addAttribute("mediaUrl", url);
String suffix = fileAttribute.getSuffix(); return MEDIA_FILE_PREVIEW_PAGE;
if ("flv".equalsIgnoreCase(suffix)) {
return "flv";
}
return "media";
} }

6
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); return getPreviewType(model, fileAttribute, officePreviewType, baseUrl, pdfName, outFilePath, fileHandlerService, OFFICE_PREVIEW_TYPE_IMAGE, otherFilePreview);
} }
model.addAttribute("pdfUrl", pdfName); 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) { 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("imgurls", imageUrls);
model.addAttribute("currentUrl", imageUrls.get(0)); model.addAttribute("currentUrl", imageUrls.get(0));
if (officePreviewTypeImage.equals(officePreviewType)) { if (officePreviewTypeImage.equals(officePreviewType)) {
return "officePicture"; return OFFICE_PICTURE_FILE_PREVIEW_PAGE;
} else { } else {
return "picture"; return PICTURE_FILE_PREVIEW_PAGE;
} }
} }
} }

1
server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java

@ -12,7 +12,6 @@ import org.springframework.ui.Model;
@Service @Service
public class OtherFilePreviewImpl implements FilePreview { public class OtherFilePreviewImpl implements FilePreview {
public static final String NOT_SUPPORTED_FILE_PAGE = "fileNotSupported";
@Override @Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) { public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {

6
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("imgurls", imageUrls);
model.addAttribute("currentUrl", imageUrls.get(0)); model.addAttribute("currentUrl", imageUrls.get(0));
if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType)) { if (OfficeFilePreviewImpl.OFFICE_PREVIEW_TYPE_IMAGE.equals(officePreviewType)) {
return "officePicture"; return OFFICE_PICTURE_FILE_PREVIEW_PAGE;
} else { } else {
return "picture"; return PICTURE_FILE_PREVIEW_PAGE;
} }
} else { } else {
// 不是http开头,浏览器不能直接访问,需下载到本地 // 不是http开头,浏览器不能直接访问,需下载到本地
@ -79,6 +79,6 @@ public class PdfFilePreviewImpl implements FilePreview {
model.addAttribute("pdfUrl", url); model.addAttribute("pdfUrl", url);
} }
} }
return "pdf"; return PDF_FILE_PREVIEW_PAGE;
} }
} }

2
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("imgurls", imgUrls);
model.addAttribute("currentUrl", url); model.addAttribute("currentUrl", url);
} }
return "picture"; return PICTURE_FILE_PREVIEW_PAGE;
} }
} }

2
server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java

@ -46,7 +46,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
if (!model.containsAttribute(TEXT_TYPE)) { if (!model.containsAttribute(TEXT_TYPE)) {
model.addAttribute(TEXT_TYPE, DEFAULT_TEXT_TYPE); model.addAttribute(TEXT_TYPE, DEFAULT_TEXT_TYPE);
} }
return "txt"; return TXT_FILE_PREVIEW_PAGE;
} }
} }

Loading…
Cancel
Save