mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-05 07:47:33 +00:00
1.修复不支持文件类型提示时抛异常的问题
2.添加多媒体文件预览支持,如mp4,mp3等文件
This commit is contained in:
@@ -10,7 +10,8 @@ public enum FileType {
|
|||||||
office("officeFilePreviewImpl"),
|
office("officeFilePreviewImpl"),
|
||||||
simText("simTextFilePreviewImpl"),
|
simText("simTextFilePreviewImpl"),
|
||||||
pdf("pdfFilePreviewImpl"),
|
pdf("pdfFilePreviewImpl"),
|
||||||
other("otherFilePreviewImpl");
|
other("otherFilePreviewImpl"),
|
||||||
|
media("mediaFilePreviewImpl");
|
||||||
|
|
||||||
private String instanceName;
|
private String instanceName;
|
||||||
FileType(String instanceName){
|
FileType(String instanceName){
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package cn.keking.service.impl;
|
||||||
|
|
||||||
|
import cn.keking.service.FilePreview;
|
||||||
|
import cn.keking.utils.FileUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
/**
|
||||||
|
* @author : kl
|
||||||
|
* @authorboke : kailing.pub
|
||||||
|
* @create : 2018-03-25 上午11:58
|
||||||
|
* @description:
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class MediaFilePreviewImpl implements FilePreview {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
FileUtils fileUtils;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String filePreviewHandle(String url, Model model) {
|
||||||
|
model.addAttribute("mediaUrl", url);
|
||||||
|
return "media";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package cn.keking.service.impl;
|
package cn.keking.service.impl;
|
||||||
|
|
||||||
|
import cn.keking.model.FileAttribute;
|
||||||
import cn.keking.service.FilePreview;
|
import cn.keking.service.FilePreview;
|
||||||
|
import cn.keking.utils.FileUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
@@ -10,8 +13,14 @@ import org.springframework.ui.Model;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class OtherFilePreviewImpl implements FilePreview {
|
public class OtherFilePreviewImpl implements FilePreview {
|
||||||
|
@Autowired
|
||||||
|
FileUtils fileUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String filePreviewHandle(String url, Model model) {
|
public String filePreviewHandle(String url, Model model) {
|
||||||
|
FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
|
||||||
|
|
||||||
|
model.addAttribute("fileType",fileAttribute.getSuffix());
|
||||||
model.addAttribute("msg", "系统还不支持该格式文件的在线预览," +
|
model.addAttribute("msg", "系统还不支持该格式文件的在线预览," +
|
||||||
"如有需要请按下方显示的邮箱地址联系系统维护人员");
|
"如有需要请按下方显示的邮箱地址联系系统维护人员");
|
||||||
return "fileNotSupported";
|
return "fileNotSupported";
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public class SimTextFilePreviewImpl implements FilePreview{
|
|||||||
ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName);
|
ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName);
|
||||||
if (0 != response.getCode()) {
|
if (0 != response.getCode()) {
|
||||||
model.addAttribute("msg", response.getMsg());
|
model.addAttribute("msg", response.getMsg());
|
||||||
|
model.addAttribute("fileType",fileAttribute.getSuffix());
|
||||||
return "fileNotSupported";
|
return "fileNotSupported";
|
||||||
}
|
}
|
||||||
model.addAttribute("ordinaryUrl", response.getMsg());
|
model.addAttribute("ordinaryUrl", response.getMsg());
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public class FileUtils {
|
|||||||
|
|
||||||
@Value("${simText}")
|
@Value("${simText}")
|
||||||
String[] simText;
|
String[] simText;
|
||||||
|
|
||||||
|
@Value("${media}")
|
||||||
|
String[] media;
|
||||||
/**
|
/**
|
||||||
* 已转换过的文件集合(redis缓存)
|
* 已转换过的文件集合(redis缓存)
|
||||||
* @return
|
* @return
|
||||||
@@ -80,6 +83,9 @@ public class FileUtils {
|
|||||||
if (Arrays.asList(simText).contains(fileType.toLowerCase())) {
|
if (Arrays.asList(simText).contains(fileType.toLowerCase())) {
|
||||||
return FileType.simText;
|
return FileType.simText;
|
||||||
}
|
}
|
||||||
|
if (Arrays.asList(media).contains(fileType.toLowerCase())) {
|
||||||
|
return FileType.media;
|
||||||
|
}
|
||||||
if("pdf".equalsIgnoreCase(fileType)){
|
if("pdf".equalsIgnoreCase(fileType)){
|
||||||
return FileType.pdf;
|
return FileType.pdf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#=============================================#spring Redisson配置#===================================#
|
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
|
||||||
spring.redisson.address = 192.168.1.204:6379
|
spring.redisson.address = 127.0.0.1:6379
|
||||||
##资源映射路径(因为jar方式运行的原因)
|
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<28><>Ϊjar<61><72>ʽ<EFBFBD><CABD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><D4AD>)
|
||||||
file.dir = C:\\Users\\yudian\\Desktop\\dev\\
|
file.dir = /Users/chenkailing/test/
|
||||||
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
||||||
## openoffice相关配置
|
## openoffice<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
office.home = C:\\Program Files (x86)\\OpenOffice 4
|
office.home = /Applications/LibreOffice.app/Contents
|
||||||
server.tomcat.uri-encoding = UTF-8
|
server.tomcat.uri-encoding = UTF-8
|
||||||
converted.file.charset = GBK
|
converted.file.charset = GBK
|
||||||
#======================================#文件上传限制#======================================#
|
#======================================#<EFBFBD>ļ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>#======================================#
|
||||||
spring.http.multipart.max-file-size=100MB
|
spring.http.multipart.max-file-size=100MB
|
||||||
spring.http.multipart.max-request-size=100MB
|
spring.http.multipart.max-request-size=100MB
|
||||||
## 支持的类文本格式的文件类型
|
## ֧<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
simText = txt,html,xml,java,properties,mp3,mp4,sql
|
simText = txt,html,xml,java,properties,sql
|
||||||
|
media=mp3,mp4,flv,rmvb
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
#=============================================#spring Redisson配置#===================================#
|
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
|
||||||
spring.redisson.address = 10.19.140.7:6379
|
spring.redisson.address = 10.19.140.7:6379
|
||||||
spring.redisson.database = 0
|
spring.redisson.database = 0
|
||||||
##资源映射路径(因为jar方式运行的原因)
|
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<28><>Ϊjar<61><72>ʽ<EFBFBD><CABD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><D4AD>)
|
||||||
file.dir = /data/file-preview/convertedFile/
|
file.dir = /data/file-preview/convertedFile/
|
||||||
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
||||||
## openoffice相关配置
|
## openoffice<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
office.home = /opt/openoffice4
|
office.home = /opt/openoffice4
|
||||||
|
|
||||||
## 编码设置
|
## <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
server.tomcat.uri-encoding = utf-8
|
server.tomcat.uri-encoding = utf-8
|
||||||
converted.file.charset = utf-8
|
converted.file.charset = utf-8
|
||||||
## 文件上传最大值
|
## <EFBFBD>ļ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||||
spring.http.multipart.max-file-size = 100MB
|
spring.http.multipart.max-file-size = 100MB
|
||||||
|
|
||||||
## 支持的类文本格式的文件类型
|
## ֧<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,mp3,mp4,css,cnf
|
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,css,cnf
|
||||||
|
|
||||||
|
media=mp3,mp4,flv
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
#=============================================#spring Redisson配置#===================================#
|
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
|
||||||
spring.redisson.address = 192.168.1.204:6379
|
spring.redisson.address = 192.168.1.204:6379
|
||||||
spring.redisson.database = 3
|
spring.redisson.database = 3
|
||||||
##资源映射路径(因为jar方式运行的原因)
|
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<28><>Ϊjar<61><72>ʽ<EFBFBD><CABD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><D4AD>)
|
||||||
file.dir = /data/filepreview/
|
file.dir = /data/filepreview/
|
||||||
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
|
||||||
## openoffice相关配置
|
## openoffice<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
openOfficePath = 123
|
openOfficePath = 123
|
||||||
office.home = /opt/openoffice4
|
office.home = /opt/openoffice4
|
||||||
server.tomcat.uri-encoding = utf-8
|
server.tomcat.uri-encoding = utf-8
|
||||||
converted.file.charset = utf-8
|
converted.file.charset = utf-8
|
||||||
spring.http.multipart.max-file-size = 100MB
|
spring.http.multipart.max-file-size = 100MB
|
||||||
## 支持的类文本格式的文件类型
|
## ֧<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,mp3,mp4,css,cnf
|
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,css,cnf
|
||||||
|
media=mp3,mp4,flv
|
||||||
1
jodconverter-web/src/main/resources/static/plyr/plyr.css
Executable file
1
jodconverter-web/src/main/resources/static/plyr/plyr.css
Executable file
File diff suppressed because one or more lines are too long
2
jodconverter-web/src/main/resources/static/plyr/plyr.js
Executable file
2
jodconverter-web/src/main/resources/static/plyr/plyr.js
Executable file
File diff suppressed because one or more lines are too long
1
jodconverter-web/src/main/resources/static/plyr/plyr.svg
Executable file
1
jodconverter-web/src/main/resources/static/plyr/plyr.svg
Executable file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 3.7 KiB |
24
jodconverter-web/src/main/resources/web/media.ftl
Normal file
24
jodconverter-web/src/main/resources/web/media.ftl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>多媒体文件预览</title>
|
||||||
|
<link rel="stylesheet" href="plyr/plyr.css">
|
||||||
|
</head>
|
||||||
|
<style>
|
||||||
|
body{background-color: #262626}
|
||||||
|
.m{ margin-left: auto; margin-right: auto; width:640px; margin-top: 100px; }
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div class="m">
|
||||||
|
<video controls>
|
||||||
|
<source src="${mediaUrl}">
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
<script src="plyr/plyr.js"></script>
|
||||||
|
<script>
|
||||||
|
plyr.setup();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user