Commit 00fbb5cd authored by chenkailing's avatar chenkailing

Merge branch 'master' of https://github.com/kekingcn/kkFileView

parents 50dd7c1b fbafcd5c
...@@ -28,5 +28,5 @@ ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ...@@ -28,5 +28,5 @@ ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH $PATH:$JAVA_HOME/bin ENV PATH $PATH:$JAVA_HOME/bin
ENV LANG zh_CN.UTF-8 ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8 ENV LC_ALL zh_CN.UTF-8
ENV KKFILEVIEW_BIN_FOLDER /opt/kkFileView-3.3.0/bin ENV KKFILEVIEW_BIN_FOLDER /opt/kkFileView-3.3.1/bin
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider","-Dspring.config.location=/opt/kkFileView-3.3.0/config/application.properties","-jar","/opt/kkFileView-3.3.0/bin/kkFileView-3.3.0.jar"] ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider","-Dspring.config.location=/opt/kkFileView-3.3.1/config/application.properties","-jar","/opt/kkFileView-3.3.1/bin/kkFileView-3.3.1.jar"]
\ No newline at end of file \ No newline at end of file
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
此项目为文件文档在线预览项目解决方案,对标业内付费产品有【[永中office](http://dcs.yozosoft.com/)】【[office365](http://www.officeweb365.com/)】【[idocv](https://www.idocv.com/)】等,在取得公司高层同意后以Apache协议开源出来反哺社区,在此特别感谢@唐老大的支持以及@端木详笑的贡献。该项目使用流行的spring boot搭建,易上手和部署,基本支持主流办公文档的在线预览,如doc,docx,Excel,pdf,txt,zip,rar,图片等等 此项目为文件文档在线预览项目解决方案,对标业内付费产品有【[永中office](http://dcs.yozosoft.com/)】【[office365](http://www.officeweb365.com/)】【[idocv](https://www.idocv.com/)】等,在取得公司高层同意后以Apache协议开源出来反哺社区,在此特别感谢@唐老大的支持以及@端木详笑的贡献。该项目使用流行的spring boot搭建,易上手和部署,基本支持主流办公文档的在线预览,如doc,docx,Excel,pdf,txt,zip,rar,图片等等
### 项目特性 ### 项目特性
1. 支持office,pdf, cad等办公文档 1. 支持 office, pdf, cad 等办公文档
1. 支持txt,java,php,py,md,js,css等所有纯文本 1. 支持 txt, xml(渲染), md(渲染), java, php, py, js, css 等所有纯文本
1. 支持zip,rar,jar,tar,gzip等压缩包 1. 支持 zip, rar, jar, tar, gzip 等压缩包
1. 支持jpg,jpeg,png,gif等图片预览(翻转,缩放,镜像) 1. 支持 jpg, jpeg, png, gif, tif, tiff 等图片预览(翻转,缩放,镜像)
1. 使用spring boot开发,预览服务搭建部署非常简便 1. 使用 spring-boot 开发,预览服务搭建部署非常简便
1. rest接口提供服务,跨平台特性(java,php,python,go,php,....)都支持,应用接入简单方便 1. rest 接口提供服务,跨语言、跨平台特性(java,php,python,go,php,....)都支持,应用接入简单方便
1. 抽象预览服务接口,方便二次开发,非常方便添加其他类型文件预览支持 1. 抽象预览服务接口,方便二次开发,非常方便添加其他类型文件预览支持
1. 最最重要Apache协议开源,代码pull下来想干嘛就干嘛 1. 最最重要 Apache 协议开源,代码 pull 下来想干嘛就干嘛
### 官网及文档 ### 官网及文档
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
1. English document:https://gitee.com/kekingcn/file-online-preview/blob/master/README.en.md 1. English document:https://gitee.com/kekingcn/file-online-preview/blob/master/README.en.md
### 联系我们,加入组织 ### 联系我们,加入组织
> 我们会用心回答解决大家在项目使用中的问题,也请大家在提问前至少Google或baidu过,珍爱生命远离无效的交流沟通 > 我们会用心回答解决大家在项目使用中的问题,也请大家在提问前至少 Google 或 baidu 过,珍爱生命远离无效的交流沟通
![](./doc/KK开源技术交流2群群聊二维码.png) ![](./doc/KK开源技术交流2群群聊二维码.png)
...@@ -99,16 +99,40 @@ pdf预览模式预览效果如下 ...@@ -99,16 +99,40 @@ pdf预览模式预览效果如下
- jodconverter - jodconverter
> 依赖外部环境 > 依赖外部环境
- redis (可选,默认不用) - redis (可选,默认不用)
- OpenOffice或者LibreOffice(Windows下已内置,Linux会自动安装,Mac OS下需要手动安装) - OpenOffice 或者 LibreOffice( Windows 下已内置,Linux 脚本启动模式会自动安装,Mac OS 下需要手动安装)
1. 第一步:pull项目https://github.com/kekingcn/file-online-preview.git 1. 第一步:pull 项目 https://github.com/kekingcn/file-online-preview.git
3. 第二步:运行FilePreviewApplication的main方法,服务启动后,访问http://localhost:8012/ 3. 第二步:运行 ServerMain 的 main 方法,服务启动后,访问 http://localhost:8012/
会看到如下界面,代表服务启动成功 会看到如下界面,代表服务启动成功
![输入图片说明](https://gitee.com/uploads/images/2017/1213/100221_ea15202e_492218.png "屏幕截图.png") ![输入图片说明](https://gitee.com/uploads/images/2017/1213/100221_ea15202e_492218.png "屏幕截图.png")
### 历史更新记录 ### 历史更新记录
> 2021年1月28日 :
2020农历年最后一个版本发布,主要包含了部分 UI 改进,和解决了 QQ 群友、 Issue 里反馈的 Bug 修复,最最重要的是发个新版,过个好年
1. 引入galimatias,解决不规范文件名导致文件下载异常
2. 更新index接入演示界面UI风格
3. 更新markdown文件预览UI风格
4. 更新XML文件预览UI风格,调整类文本预览架构,更方便扩展
5. 更新simTxT文件预览UI风格
6. 调整多图连续预览上下翻图的UI
7. 采用apache-common-io包简化所有的文件下载io操作
8. XML文件预览支持切换纯文本模式
9. 增强url base64解码失败时的提示信息
10. 修复导包错误以及图片预览 bug
11. 修复发行包运行时找不到日志目录的问题
12. 修复压缩包内多图连续预览的bug
13. 修复大小写文件类型后缀没通用匹配的问题
14. 指定Base64转码采用Apache Commons-code中的实现,修复base64部分jdk版本下出现的异常
15. 修复类文本类型HTML文件预览的bug
16. 修复:dwg文件预览时无法在jpg和pdf两种类型之间切换
17. escaping of dangerous characters to prevent reflected xss
18. 修复重复编码导致文档转图片预览失败的问题&编码规范
> 2020年12月27日 : > 2020年12月27日 :
2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设 2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设
...@@ -183,5 +207,13 @@ pdf预览模式预览效果如下 ...@@ -183,5 +207,13 @@ pdf预览模式预览效果如下
1. 引入pdf.js预览doc等文件,支持doc标题生成pdf预览菜单,支持手机端预览 1. 引入pdf.js预览doc等文件,支持doc标题生成pdf预览菜单,支持手机端预览
### 使用登记 ### 使用登记
如果这个项目解决了你的实际问题,可在https://gitee.com/kekingcn/file-online-preview/issues/IGSBV 如果这个项目解决了你的实际问题,可在 https://gitee.com/kekingcn/file-online-preview/issues/IGSBV
登记下,如果节省了你的三方预览服务费用,也愿意支持下的话,可点击下方【捐助】请作者喝杯咖啡,也是非常感谢 登记下,如果节省了你的三方预览服务费用,也愿意支持下的话,可点击下方【捐助】请作者喝杯咖啡,也是非常感谢
### Stars 趋势图
#### Gitee
[![Stargazers over time](https://whnb.wang/img/kekingcn/file-online-preview)](https://whnb.wang/kekingcn/file-online-preview?e=86400)
#### GitHub
[![Stargazers over time](https://starchart.cc/kekingcn/kkFileView.svg)](https://starchart.cc/kekingcn/kkFileView)
...@@ -7,9 +7,7 @@ ...@@ -7,9 +7,7 @@
<artifactId>office-plugin</artifactId> <artifactId>office-plugin</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories> <repositories>
<repository> <repository>
<!-- required for org.hyperic:sigar --> <!-- required for org.hyperic:sigar -->
......
...@@ -2,15 +2,23 @@ ...@@ -2,15 +2,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>cn.keking</groupId> <groupId>cn.keking</groupId>
<artifactId>filepreview</artifactId> <artifactId>filepreview</artifactId>
<version>3.3.0</version> <version>3.3.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<modules> <modules>
<module>office-plugin</module> <module>office-plugin</module>
<module>server</module> <module>server</module>
</modules> </modules>
<packaging>pom</packaging>
<profiles> <profiles>
<profile> <profile>
......
...@@ -5,20 +5,14 @@ ...@@ -5,20 +5,14 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version> <version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.keking</groupId> <groupId>cn.keking</groupId>
<artifactId>kkFileView</artifactId> <artifactId>kkFileView</artifactId>
<version>3.3.0</version> <version>3.3.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<repositories> <repositories>
<repository> <repository>
...@@ -27,6 +21,7 @@ ...@@ -27,6 +21,7 @@
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url> <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
...@@ -197,6 +192,7 @@ ...@@ -197,6 +192,7 @@
<version>0.2.1</version> <version>0.2.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>
<resource> <resource>
......
...@@ -6,4 +6,4 @@ echo Starting kkFileView... ...@@ -6,4 +6,4 @@ echo Starting kkFileView...
echo Please check log file in ../log/kkFileView.log for more information echo Please check log file in ../log/kkFileView.log for more information
echo You can get help in our official homesite: https://kkFileView.keking.cn echo You can get help in our official homesite: https://kkFileView.keking.cn
echo If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers echo If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers
java -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider -Dspring.config.location=..\config\application.properties -jar kkFileView-3.3.0.jar -> ..\log\kkFileView.log java -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider -Dspring.config.location=..\config\application.properties -jar kkFileView-3.3.1.jar -> ..\log\kkFileView.log
\ No newline at end of file \ No newline at end of file
...@@ -29,4 +29,4 @@ echo "Starting kkFileView..." ...@@ -29,4 +29,4 @@ echo "Starting kkFileView..."
echo "Please execute ./showlog.sh to check log for more information" echo "Please execute ./showlog.sh to check log for more information"
echo "You can get help in our official homesite: https://kkFileView.keking.cn" echo "You can get help in our official homesite: https://kkFileView.keking.cn"
echo "If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers" echo "If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers"
nohup java -Dfile.encoding=UTF-8 -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider -Dspring.config.location=../config/application.properties -jar kkFileView-3.3.0.jar > ../log/kkFileView.log 2>&1 & nohup java -Dfile.encoding=UTF-8 -Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider -Dspring.config.location=../config/application.properties -jar kkFileView-3.3.1.jar > ../log/kkFileView.log 2>&1 &
#######################################不可动态配置,需要重启生效####################################### #######################################不可动态配置,需要重启生效#######################################
server.port = ${KK_SERVER_PORT:8012} server.port = ${KK_SERVER_PORT:8012}
server.context-path = ${KK_CONTEXT_PATH:/} server.servlet.context-path= ${KK_CONTEXT_PATH:/}
spring.http.encoding.charset = utf8 server.servlet.encoding.charset = utf-8
#文件上传限制
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
## Freemarker 配置 ## Freemarker 配置
spring.freemarker.template-loader-path = classpath:/web/ spring.freemarker.template-loader-path = classpath:/web/
spring.freemarker.cache = false spring.freemarker.cache = false
...@@ -13,11 +16,6 @@ spring.freemarker.expose-session-attributes = true ...@@ -13,11 +16,6 @@ spring.freemarker.expose-session-attributes = true
spring.freemarker.request-context-attribute = request spring.freemarker.request-context-attribute = request
spring.freemarker.suffix = .ftl spring.freemarker.suffix = .ftl
server.tomcat.uri-encoding = UTF-8
#文件上传限制
spring.http.multipart.max-request-size=500MB
spring.http.multipart.max-file-size=500MB
#文件资源路径(默认为打包根路径下的file目录下) #文件资源路径(默认为打包根路径下的file目录下)
#file.dir = D:\\kkFileview\\ #file.dir = D:\\kkFileview\\
file.dir = ${KK_FILE_DIR:default} file.dir = ${KK_FILE_DIR:default}
......
[#ftl] [#ftl]
[#-- @implicitly included --] [#-- @implicitly included --]
[#-- @ftlvariable name="currentUrl" type="java.lang.String" --]
[#-- @ftlvariable name="file" type="cn.keking.model.FileAttribute" --] [#-- @ftlvariable name="file" type="cn.keking.model.FileAttribute" --]
[#-- @ftlvariable name="fileName" type="java.lang.String" --] [#-- @ftlvariable name="fileName" type="java.lang.String" --]
[#-- @ftlvariable name="fileTree" type="java.lang.String" --] [#-- @ftlvariable name="fileTree" type="java.lang.String" --]
......
package cn.keking; package cn.keking;
import org.springframework.boot.SpringApplication; import cn.keking.config.AppBanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.StopWatch;
@SpringBootApplication @SpringBootApplication
@EnableScheduling @EnableScheduling
@ComponentScan(value = "cn.keking.*") @ComponentScan(value = "cn.keking.*")
public class ServerMain { public class ServerMain {
public static void main(String[] args) { private static final Logger logger = LoggerFactory.getLogger(ServerMain.class);
ServerMain.staticInitSystemProperty();
SpringApplication.run(ServerMain.class, args); public static void main(String[] args) {
} StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = new SpringApplicationBuilder(ServerMain.class)
.logStartupInfo(false)
.banner(new AppBanner())
.run(args);
stopWatch.stop();
Integer port = context.getBean(ServerProperties.class).getPort();
logger.info("kkFileView 服务启动完成,耗时:{}s,演示页请访问: http://127.0.0.1:{} ", stopWatch.getTotalTimeSeconds(), port);
}
private static void staticInitSystemProperty(){
//pdfbox兼容低版本jdk
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
}
} }
package cn.keking.config;
import org.springframework.boot.Banner;
import org.springframework.core.env.Environment;
import java.io.PrintStream;
/**
* @author kl (http://kailing.pub)
* @since 2021/2/8
*/
public class AppBanner implements Banner {
@Override
public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
out.println(
" _ _ ______ _ _ __ __ _ \n" +
" | | | | | ____| (_) | | \\ \\ / / (_) \n" +
" | | __ | | __ | |__ _ | | ___ \\ \\ / / _ ___ __ __\n" +
" | |/ / | |/ / | __| | | | | / _ \\ \\ \\/ / | | / _ \\ \\ \\ /\\ / /\n" +
" | < | < | | | | | | | __/ \\ / | | | __/ \\ V V / \n" +
" |_|\\_\\ |_|\\_\\ |_| |_| |_| \\___| \\/ |_| \\___| \\_/\\_/ \n" +
" \n" +
" => Spring Boot :: (v2.4.2) QQ1 :: 613025121\n" +
" => kkFileView :: (v3.3.1) QQ2 :: 484680571\n" +
" => github :: https://github.com/kekingcn/kkFileView\n" +
" => gitee :: https://gitee.com/kekingcn/file-online-preview\n");
}
}
...@@ -16,6 +16,11 @@ import java.util.Set; ...@@ -16,6 +16,11 @@ import java.util.Set;
@Component @Component
public class ConfigConstants { public class ConfigConstants {
static {
//pdfbox兼容低版本jdk
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
}
private static Boolean CACHE_ENABLED; private static Boolean CACHE_ENABLED;
private static String[] SIM_TEXT = {}; private static String[] SIM_TEXT = {};
private static String[] MEDIA = {}; private static String[] MEDIA = {};
......
...@@ -11,52 +11,57 @@ import java.util.Map; ...@@ -11,52 +11,57 @@ import java.util.Map;
*/ */
public enum FileType { public enum FileType {
picture("pictureFilePreviewImpl"), PICTURE("pictureFilePreviewImpl"),
compress("compressFilePreviewImpl"), COMPRESS("compressFilePreviewImpl"),
office("officeFilePreviewImpl"), OFFICE("officeFilePreviewImpl"),
simText("simTextFilePreviewImpl"), SIMTEXT("simTextFilePreviewImpl"),
pdf("pdfFilePreviewImpl"), PDF("pdfFilePreviewImpl"),
other("otherFilePreviewImpl"), OTHER("otherFilePreviewImpl"),
media("mediaFilePreviewImpl"), MEDIA("mediaFilePreviewImpl"),
markdown("markdownFilePreviewImpl"), MARKDOWN("markdownFilePreviewImpl"),
xml("xmlFilePreviewImpl"), XML("xmlFilePreviewImpl"),
flv("flvFilePreviewImpl"), FLV("flvFilePreviewImpl"),
cad("cadFilePreviewImpl"); CAD("cadFilePreviewImpl"),
TIFF("tiffFilePreviewImpl");
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[] TIFF_TYPES = {"tif", "tiff"};
private static final String[] SSIM_TEXT_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<>();
static { static {
for (String office : OFFICE_TYPES) { for (String office : OFFICE_TYPES) {
FILE_TYPE_MAPPER.put(office, FileType.office); FILE_TYPE_MAPPER.put(office, FileType.OFFICE);
} }
for (String picture : PICTURE_TYPES) { for (String picture : PICTURE_TYPES) {
FILE_TYPE_MAPPER.put(picture, FileType.picture); FILE_TYPE_MAPPER.put(picture, FileType.PICTURE);
} }
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 : SSIM_TEXT_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) {
FILE_TYPE_MAPPER.put(media, FileType.media); FILE_TYPE_MAPPER.put(media, FileType.MEDIA);
} }
FILE_TYPE_MAPPER.put("md", FileType.markdown); for (String tif : TIFF_TYPES) {
FILE_TYPE_MAPPER.put("xml", FileType.xml); FILE_TYPE_MAPPER.put(tif, FileType.TIFF);
FILE_TYPE_MAPPER.put("pdf", FileType.pdf); }
FILE_TYPE_MAPPER.put("dwg", FileType.cad); FILE_TYPE_MAPPER.put("md", FileType.MARKDOWN);
FILE_TYPE_MAPPER.put("flv", FileType.flv); 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){ private static FileType to(String fileType) {
return FILE_TYPE_MAPPER.getOrDefault(fileType,other); return FILE_TYPE_MAPPER.getOrDefault(fileType, OTHER);
} }
/** /**
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型) * 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
* *
......
...@@ -68,7 +68,7 @@ public class CompressFileReader { ...@@ -68,7 +68,7 @@ public class CompressFileReader {
String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName); String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
parentName = (level - 1) + "_" + parentName; parentName = (level - 1) + "_" + parentName;
FileType type = FileType.typeFromUrl(childName); FileType type = FileType.typeFromUrl(childName);
if (type.equals(FileType.picture)) {//添加图片文件到图片列表 if (type.equals(FileType.PICTURE)) {//添加图片文件到图片列表
imgUrls.add(baseUrl + childName); imgUrls.add(baseUrl + childName);
} }
FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey); FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey);
...@@ -121,7 +121,7 @@ public class CompressFileReader { ...@@ -121,7 +121,7 @@ public class CompressFileReader {
} }
String parentName = getLast2FileName(fullName, "\\", archiveFileName); String parentName = getLast2FileName(fullName, "\\", archiveFileName);
FileType type = FileType.typeFromUrl(childName); FileType type = FileType.typeFromUrl(childName);
if (type.equals(FileType.picture)) {//添加图片文件到图片列表 if (type.equals(FileType.PICTURE)) {//添加图片文件到图片列表
imgUrls.add(baseUrl + childName); imgUrls.add(baseUrl + childName);
} }
FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey); FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey);
...@@ -164,7 +164,7 @@ public class CompressFileReader { ...@@ -164,7 +164,7 @@ public class CompressFileReader {
String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName); String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
parentName = (level - 1) + "_" + parentName; parentName = (level - 1) + "_" + parentName;
FileType type = FileType.typeFromUrl(childName); FileType type = FileType.typeFromUrl(childName);
if (type.equals(FileType.picture)) {//添加图片文件到图片列表 if (type.equals(FileType.PICTURE)) {//添加图片文件到图片列表
imgUrls.add(baseUrl + childName); imgUrls.add(baseUrl + childName);
} }
FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey); FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey);
......
...@@ -62,7 +62,7 @@ public class FileConvertQueueTask { ...@@ -62,7 +62,7 @@ public class FileConvertQueueTask {
FileAttribute fileAttribute = fileHandlerService.getFileAttribute(url,null); FileAttribute fileAttribute = fileHandlerService.getFileAttribute(url,null);
FileType fileType = fileAttribute.getType(); FileType fileType = fileAttribute.getType();
logger.info("正在处理预览转换任务,url:{},预览类型:{}", url, fileType); logger.info("正在处理预览转换任务,url:{},预览类型:{}", url, fileType);
if(fileType.equals(FileType.compress) || fileType.equals(FileType.office) || fileType.equals(FileType.cad)) { if(fileType.equals(FileType.COMPRESS) || fileType.equals(FileType.OFFICE) || fileType.equals(FileType.CAD)) {
FilePreview filePreview = previewFactory.get(fileAttribute); FilePreview filePreview = previewFactory.get(fileAttribute);
filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute); filePreview.filePreviewHandle(url, new ExtendedModelMap(), fileAttribute);
} else { } else {
......
...@@ -178,14 +178,15 @@ public class FileHandlerService { ...@@ -178,14 +178,15 @@ public class FileHandlerService {
String pdfFolder = pdfName.substring(0, pdfName.length() - 4); String pdfFolder = pdfName.substring(0, pdfName.length() - 4);
String urlPrefix; String urlPrefix;
try { try {
urlPrefix = baseUrl + URLEncoder.encode(URLEncoder.encode(pdfFolder, uriEncoding).replaceAll("\\+", "%20"), uriEncoding); urlPrefix = baseUrl + URLEncoder.encode(pdfFolder, uriEncoding).replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
logger.error("UnsupportedEncodingException", e); logger.error("UnsupportedEncodingException", e);
urlPrefix = baseUrl + pdfFolder; urlPrefix = baseUrl + pdfFolder;
} }
if (imageCount != null && imageCount > 0) { if (imageCount != null && imageCount > 0) {
for (int i = 0; i < imageCount; i++) for (int i = 0; i < imageCount; i++) {
imageUrls.add(urlPrefix + "/" + i + imageFileSuffix); imageUrls.add(urlPrefix + "/" + i + imageFileSuffix);
}
return imageUrls; return imageUrls;
} }
try { try {
......
...@@ -14,6 +14,7 @@ public interface FilePreview { ...@@ -14,6 +14,7 @@ public interface FilePreview {
String COMPRESS_FILE_PREVIEW_PAGE = "compress"; String COMPRESS_FILE_PREVIEW_PAGE = "compress";
String MEDIA_FILE_PREVIEW_PAGE = "media"; String MEDIA_FILE_PREVIEW_PAGE = "media";
String PICTURE_FILE_PREVIEW_PAGE = "picture"; String PICTURE_FILE_PREVIEW_PAGE = "picture";
String TIFF_FILE_PREVIEW_PAGE = "tiff";
String OFFICE_PICTURE_FILE_PREVIEW_PAGE = "officePicture"; String OFFICE_PICTURE_FILE_PREVIEW_PAGE = "officePicture";
String TXT_FILE_PREVIEW_PAGE = "txt"; String TXT_FILE_PREVIEW_PAGE = "txt";
String EXEL_FILE_PREVIEW_PAGE = "html"; String EXEL_FILE_PREVIEW_PAGE = "html";
......
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;
/**
* tiff 图片文件处理
* @author kl (http://kailing.pub)
* @since 2021/2/8
*/
@Service
public class TiffFilePreviewImpl implements FilePreview {
private final PictureFilePreviewImpl pictureFilePreview;
public TiffFilePreviewImpl(PictureFilePreviewImpl pictureFilePreview) {
this.pictureFilePreview = pictureFilePreview;
}
@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
pictureFilePreview.filePreviewHandle(url,model,fileAttribute);
return TIFF_FILE_PREVIEW_PAGE;
}
}
...@@ -4,7 +4,7 @@ import cn.keking.config.ConfigConstants; ...@@ -4,7 +4,7 @@ import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute; import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse; import cn.keking.model.ReturnResponse;
import io.mola.galimatias.GalimatiasParseException; import io.mola.galimatias.GalimatiasParseException;
import jodd.io.NetUtil; import org.apache.commons.io.FileUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -39,7 +39,7 @@ public class DownloadUtils { ...@@ -39,7 +39,7 @@ public class DownloadUtils {
URL url = WebUtils.normalizedURL(urlStr); URL url = WebUtils.normalizedURL(urlStr);
if (isHttpUrl(url)) { if (isHttpUrl(url)) {
File realFile = new File(realPath); File realFile = new File(realPath);
NetUtil.downloadFile(url.toString(),realFile); FileUtils.copyURLToFile(url,realFile);
} else if (isFtpUrl(url)) { } else if (isFtpUrl(url)) {
String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME); String ftpUsername = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME);
String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD); String ftpPassword = WebUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment