Browse Source

1.修复不支持文件类型提示时抛异常的问题

2.添加多媒体文件预览支持,如mp4,mp3等文件
pull/3/head v1.1
chenkailing 7 years ago
parent
commit
6f2001b8c9
  1. 3
      jodconverter-web/src/main/java/cn/keking/model/FileType.java
  2. 27
      jodconverter-web/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java
  3. 9
      jodconverter-web/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java
  4. 1
      jodconverter-web/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
  5. 6
      jodconverter-web/src/main/java/cn/keking/utils/FileUtils.java
  6. 19
      jodconverter-web/src/main/resources/application-dev.properties
  7. 15
      jodconverter-web/src/main/resources/application-prod.properties
  8. 11
      jodconverter-web/src/main/resources/application-uat.properties
  9. 1
      jodconverter-web/src/main/resources/static/plyr/plyr.css
  10. 2
      jodconverter-web/src/main/resources/static/plyr/plyr.js
  11. 1
      jodconverter-web/src/main/resources/static/plyr/plyr.svg
  12. 24
      jodconverter-web/src/main/resources/web/media.ftl

3
jodconverter-web/src/main/java/cn/keking/model/FileType.java

@ -10,7 +10,8 @@ public enum FileType {
office("officeFilePreviewImpl"),
simText("simTextFilePreviewImpl"),
pdf("pdfFilePreviewImpl"),
other("otherFilePreviewImpl");
other("otherFilePreviewImpl"),
media("mediaFilePreviewImpl");
private String instanceName;
FileType(String instanceName){

27
jodconverter-web/src/main/java/cn/keking/service/impl/MediaFilePreviewImpl.java

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

9
jodconverter-web/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java

@ -1,6 +1,9 @@
package cn.keking.service.impl;
import cn.keking.model.FileAttribute;
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;
@ -10,8 +13,14 @@ import org.springframework.ui.Model;
*/
@Service
public class OtherFilePreviewImpl implements FilePreview {
@Autowired
FileUtils fileUtils;
@Override
public String filePreviewHandle(String url, Model model) {
FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
model.addAttribute("fileType",fileAttribute.getSuffix());
model.addAttribute("msg", "系统还不支持该格式文件的在线预览," +
"如有需要请按下方显示的邮箱地址联系系统维护人员");
return "fileNotSupported";

1
jodconverter-web/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java

@ -30,6 +30,7 @@ public class SimTextFilePreviewImpl implements FilePreview{
ReturnResponse<String> response = simTextUtil.readSimText(decodedUrl, fileName);
if (0 != response.getCode()) {
model.addAttribute("msg", response.getMsg());
model.addAttribute("fileType",fileAttribute.getSuffix());
return "fileNotSupported";
}
model.addAttribute("ordinaryUrl", response.getMsg());

6
jodconverter-web/src/main/java/cn/keking/utils/FileUtils.java

@ -40,6 +40,9 @@ public class FileUtils {
@Value("${simText}")
String[] simText;
@Value("${media}")
String[] media;
/**
* 已转换过的文件集合(redis缓存)
* @return
@ -80,6 +83,9 @@ public class FileUtils {
if (Arrays.asList(simText).contains(fileType.toLowerCase())) {
return FileType.simText;
}
if (Arrays.asList(media).contains(fileType.toLowerCase())) {
return FileType.media;
}
if("pdf".equalsIgnoreCase(fileType)){
return FileType.pdf;
}

19
jodconverter-web/src/main/resources/application-dev.properties

@ -1,14 +1,15 @@
#=============================================#spring Redisson配置#===================================#
spring.redisson.address = 192.168.1.204:6379
##资源映射路径(因为jar方式运行的原因)
file.dir = C:\\Users\\yudian\\Desktop\\dev\\
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
spring.redisson.address = 127.0.0.1:6379
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ϊjar<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><EFBFBD>)
file.dir = /Users/chenkailing/test/
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
## openoffice相关配置
office.home = C:\\Program Files (x86)\\OpenOffice 4
## openoffice<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
office.home = /Applications/LibreOffice.app/Contents
server.tomcat.uri-encoding = UTF-8
converted.file.charset = GBK
#======================================#文件上传限制#======================================#
#======================================#<EFBFBD>ļ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>#======================================#
spring.http.multipart.max-file-size=100MB
spring.http.multipart.max-request-size=100MB
## 支持的类文本格式的文件类型
simText = txt,html,xml,java,properties,mp3,mp4,sql
## ֧<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
simText = txt,html,xml,java,properties,sql
media=mp3,mp4,flv,rmvb

15
jodconverter-web/src/main/resources/application-prod.properties

@ -1,18 +1,19 @@
#=============================================#spring Redisson配置#===================================#
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
spring.redisson.address = 10.19.140.7:6379
spring.redisson.database = 0
##资源映射路径(因为jar方式运行的原因)
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ϊjar<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><EFBFBD>)
file.dir = /data/file-preview/convertedFile/
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
## 编码设置
## <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
server.tomcat.uri-encoding = utf-8
converted.file.charset = utf-8
## 文件上传最大值
## <EFBFBD>ļ<EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
spring.http.multipart.max-file-size = 100MB
## 支持的类文本格式的文件类型
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,mp3,mp4,css,cnf
## ֧<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,css,cnf
media=mp3,mp4,flv

11
jodconverter-web/src/main/resources/application-uat.properties

@ -1,14 +1,15 @@
#=============================================#spring Redisson配置#===================================#
#=============================================#spring Redisson<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#===================================#
spring.redisson.address = 192.168.1.204:6379
spring.redisson.database = 3
##资源映射路径(因为jar方式运行的原因)
##<EFBFBD><EFBFBD>Դӳ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>Ϊjar<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>ԭ<EFBFBD><EFBFBD>)
file.dir = /data/filepreview/
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
office.home = /opt/openoffice4
server.tomcat.uri-encoding = utf-8
converted.file.charset = utf-8
spring.http.multipart.max-file-size = 100MB
## 支持的类文本格式的文件类型
simText = txt,html,xml,java,properties,sql,js,md,json,conf,ini,vue,php,py,bat,gitignore,log,htm,mp3,mp4,css,cnf
## ֧<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,css,cnf
media=mp3,mp4,flv

1
jodconverter-web/src/main/resources/static/plyr/plyr.css

File diff suppressed because one or more lines are too long

2
jodconverter-web/src/main/resources/static/plyr/plyr.js

File diff suppressed because one or more lines are too long

1
jodconverter-web/src/main/resources/static/plyr/plyr.svg

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg"><symbol id="plyr-captions-off" viewBox="0 0 18 18"><path d="M1 1c-.6 0-1 .4-1 1v11c0 .6.4 1 1 1h4.6l2.7 2.7c.2.2.4.3.7.3.3 0 .5-.1.7-.3l2.7-2.7H17c.6 0 1-.4 1-1V2c0-.6-.4-1-1-1H1zm4.52 10.15c1.99 0 3.01-1.32 3.28-2.41l-1.29-.39c-.19.66-.78 1.45-1.99 1.45-1.14 0-2.2-.83-2.2-2.34 0-1.61 1.12-2.37 2.18-2.37 1.23 0 1.78.75 1.95 1.43l1.3-.41C8.47 4.96 7.46 3.76 5.5 3.76c-1.9 0-3.61 1.44-3.61 3.7 0 2.26 1.65 3.69 3.63 3.69zm7.57 0c1.99 0 3.01-1.32 3.28-2.41l-1.29-.39c-.19.66-.78 1.45-1.99 1.45-1.14 0-2.2-.83-2.2-2.34 0-1.61 1.12-2.37 2.18-2.37 1.23 0 1.78.75 1.95 1.43l1.3-.41c-.28-1.15-1.29-2.35-3.25-2.35-1.9 0-3.61 1.44-3.61 3.7 0 2.26 1.65 3.69 3.63 3.69z" fill-rule="evenodd" fill-opacity=".5"/></symbol><symbol id="plyr-captions-on" viewBox="0 0 18 18"><path d="M1 1c-.6 0-1 .4-1 1v11c0 .6.4 1 1 1h4.6l2.7 2.7c.2.2.4.3.7.3.3 0 .5-.1.7-.3l2.7-2.7H17c.6 0 1-.4 1-1V2c0-.6-.4-1-1-1H1zm4.52 10.15c1.99 0 3.01-1.32 3.28-2.41l-1.29-.39c-.19.66-.78 1.45-1.99 1.45-1.14 0-2.2-.83-2.2-2.34 0-1.61 1.12-2.37 2.18-2.37 1.23 0 1.78.75 1.95 1.43l1.3-.41C8.47 4.96 7.46 3.76 5.5 3.76c-1.9 0-3.61 1.44-3.61 3.7 0 2.26 1.65 3.69 3.63 3.69zm7.57 0c1.99 0 3.01-1.32 3.28-2.41l-1.29-.39c-.19.66-.78 1.45-1.99 1.45-1.14 0-2.2-.83-2.2-2.34 0-1.61 1.12-2.37 2.18-2.37 1.23 0 1.78.75 1.95 1.43l1.3-.41c-.28-1.15-1.29-2.35-3.25-2.35-1.9 0-3.61 1.44-3.61 3.7 0 2.26 1.65 3.69 3.63 3.69z" fill-rule="evenodd"/></symbol><symbol id="plyr-enter-fullscreen" viewBox="0 0 18 18"><path d="M10 3h3.6l-4 4L11 8.4l4-4V8h2V1h-7zM7 9.6l-4 4V10H1v7h7v-2H4.4l4-4z"/></symbol><symbol id="plyr-exit-fullscreen" viewBox="0 0 18 18"><path d="M1 12h3.6l-4 4L2 17.4l4-4V17h2v-7H1zM16 .6l-4 4V1h-2v7h7V6h-3.6l4-4z"/></symbol><symbol id="plyr-fast-forward" viewBox="0 0 18 18"><path d="M7.875 7.171L0 1v16l7.875-6.171V17L18 9 7.875 1z"/></symbol><symbol id="plyr-muted" viewBox="0 0 18 18"><path d="M12.4 12.5l2.1-2.1 2.1 2.1 1.4-1.4L15.9 9 18 6.9l-1.4-1.4-2.1 2.1-2.1-2.1L11 6.9 13.1 9 11 11.1zM3.786 6.008H.714C.286 6.008 0 6.31 0 6.76v4.512c0 .452.286.752.714.752h3.072l4.071 3.858c.5.3 1.143 0 1.143-.602V2.752c0-.601-.643-.977-1.143-.601L3.786 6.008z"/></symbol><symbol id="plyr-pause" viewBox="0 0 18 18"><path d="M6 1H3c-.6 0-1 .4-1 1v14c0 .6.4 1 1 1h3c.6 0 1-.4 1-1V2c0-.6-.4-1-1-1zM12 1c-.6 0-1 .4-1 1v14c0 .6.4 1 1 1h3c.6 0 1-.4 1-1V2c0-.6-.4-1-1-1h-3z"/></symbol><symbol id="plyr-play" viewBox="0 0 18 18"><path d="M15.562 8.1L3.87.225C3.052-.337 2 .225 2 1.125v15.75c0 .9 1.052 1.462 1.87.9L15.563 9.9c.584-.45.584-1.35 0-1.8z"/></symbol><symbol id="plyr-restart" viewBox="0 0 18 18"><path d="M9.7 1.2l.7 6.4 2.1-2.1c1.9 1.9 1.9 5.1 0 7-.9 1-2.2 1.5-3.5 1.5-1.3 0-2.6-.5-3.5-1.5-1.9-1.9-1.9-5.1 0-7 .6-.6 1.4-1.1 2.3-1.3l-.6-1.9C6 2.6 4.9 3.2 4 4.1 1.3 6.8 1.3 11.2 4 14c1.3 1.3 3.1 2 4.9 2 1.9 0 3.6-.7 4.9-2 2.7-2.7 2.7-7.1 0-9.9L16 1.9l-6.3-.7z"/></symbol><symbol id="plyr-rewind" viewBox="0 0 18 18"><path d="M10.125 1L0 9l10.125 8v-6.171L18 17V1l-7.875 6.171z"/></symbol><symbol id="plyr-volume" viewBox="0 0 18 18"><path d="M15.6 3.3c-.4-.4-1-.4-1.4 0-.4.4-.4 1 0 1.4C15.4 5.9 16 7.4 16 9c0 1.6-.6 3.1-1.8 4.3-.4.4-.4 1 0 1.4.2.2.5.3.7.3.3 0 .5-.1.7-.3C17.1 13.2 18 11.2 18 9s-.9-4.2-2.4-5.7z"/><path d="M11.282 5.282a.909.909 0 0 0 0 1.316c.735.735.995 1.458.995 2.402 0 .936-.425 1.917-.995 2.487a.909.909 0 0 0 0 1.316c.145.145.636.262 1.018.156a.725.725 0 0 0 .298-.156C13.773 11.733 14.13 10.16 14.13 9c0-.17-.002-.34-.011-.51-.053-.992-.319-2.005-1.522-3.208a.909.909 0 0 0-1.316 0zM3.786 6.008H.714C.286 6.008 0 6.31 0 6.76v4.512c0 .452.286.752.714.752h3.072l4.071 3.858c.5.3 1.143 0 1.143-.602V2.752c0-.601-.643-.977-1.143-.601L3.786 6.008z"/></symbol></svg>

After

Width:  |  Height:  |  Size: 3.7 KiB

24
jodconverter-web/src/main/resources/web/media.ftl

@ -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>
Loading…
Cancel
Save