独立flv文件预览实现

flv
chenkailing 4 years ago
parent 9c83860e1b
commit d8a49a2862

@ -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<String, FileType> 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){

@ -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);
}

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

@ -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格式");
}

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

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

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

@ -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) {

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

@ -51,6 +51,6 @@ public class PictureFilePreviewImpl implements FilePreview {
model.addAttribute("imgurls", imgUrls);
model.addAttribute("currentUrl", url);
}
return "picture";
return PICTURE_FILE_PREVIEW_PAGE;
}
}

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

Loading…
Cancel
Save