Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e8bf0d359 | |||
| 986f562266 | |||
| 11d0441ed4 | |||
| ef46e2c51e | |||
| 0a3c03f18b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -17,7 +17,6 @@ target/
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
@ -29,4 +28,3 @@ nbdist/
|
||||
|
||||
server/src/main/cache/
|
||||
server/src/main/file/
|
||||
server/src/main/log
|
||||
@ -201,6 +201,12 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath>
|
||||
</dependency>
|
||||
<!-- url 规范化 -->
|
||||
<dependency>
|
||||
<groupId>io.mola.galimatias</groupId>
|
||||
<artifactId>galimatias</artifactId>
|
||||
<version>0.2.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
||||
@ -24,8 +24,28 @@ public class OtherFilePreviewImpl implements FilePreview {
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, FileAttribute fileAttribute, String errMsg) {
|
||||
model.addAttribute("fileType", fileAttribute.getSuffix());
|
||||
return this.notSupportedFile(model, fileAttribute.getSuffix(), errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的预览失败,导向到不支持的文件响应页面
|
||||
*
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, String errMsg) {
|
||||
return this.notSupportedFile(model, "未知", errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的预览失败,导向到不支持的文件响应页面
|
||||
*
|
||||
* @return 页面
|
||||
*/
|
||||
public String notSupportedFile(Model model, String fileType, String errMsg) {
|
||||
model.addAttribute("fileType", fileType);
|
||||
model.addAttribute("msg", errMsg);
|
||||
return NOT_SUPPORTED_FILE_PAGE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.keking.config.ConfigConstants;
|
||||
import cn.keking.model.FileAttribute;
|
||||
import cn.keking.model.FileType;
|
||||
import cn.keking.model.ReturnResponse;
|
||||
import io.mola.galimatias.GalimatiasParseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -81,7 +82,6 @@ public class DownloadUtils {
|
||||
public static byte[] getBytesFromUrl(String urlStr) throws IOException {
|
||||
InputStream is = getInputStreamFromUrl(urlStr);
|
||||
if (is == null) {
|
||||
// urlStr = URLUtil.normalize(urlStr, true, true);
|
||||
is = getInputStreamFromUrl(urlStr);
|
||||
if (is == null) {
|
||||
logger.error("文件下载异常:url:{}", urlStr);
|
||||
@ -98,13 +98,14 @@ public class DownloadUtils {
|
||||
|
||||
private static InputStream getInputStreamFromUrl(String urlStr) {
|
||||
try {
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
URL url = io.mola.galimatias.URL.parse(urlStr).toJavaURL();
|
||||
URLConnection connection = url.openConnection();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
|
||||
}
|
||||
return connection.getInputStream();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | GalimatiasParseException e) {
|
||||
logger.warn("连接url异常:url:{}", urlStr);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn.keking.service.FilePreview;
|
||||
import cn.keking.service.FilePreviewFactory;
|
||||
|
||||
import cn.keking.service.cache.CacheService;
|
||||
import cn.keking.service.impl.OtherFilePreviewImpl;
|
||||
import cn.keking.utils.DownloadUtils;
|
||||
import cn.keking.service.FileHandlerService;
|
||||
import org.slf4j.Logger;
|
||||
@ -31,21 +32,30 @@ import static cn.keking.service.FilePreview.PICTURE_FILE_PREVIEW_PAGE;
|
||||
@Controller
|
||||
public class OnlinePreviewController {
|
||||
|
||||
public static final String BASE64_DECODE_ERROR_MSG = "Base64解码失败,请检查你的 %s 是否采用 Base64 + urlEncode 双重编码了!";
|
||||
private final Logger logger = LoggerFactory.getLogger(OnlinePreviewController.class);
|
||||
|
||||
private final FilePreviewFactory previewFactory;
|
||||
private final CacheService cacheService;
|
||||
private final FileHandlerService fileHandlerService;
|
||||
private final OtherFilePreviewImpl otherFilePreview;
|
||||
|
||||
public OnlinePreviewController(FilePreviewFactory filePreviewFactory, FileHandlerService fileHandlerService, CacheService cacheService) {
|
||||
public OnlinePreviewController(FilePreviewFactory filePreviewFactory, FileHandlerService fileHandlerService, CacheService cacheService, OtherFilePreviewImpl otherFilePreview) {
|
||||
this.previewFactory = filePreviewFactory;
|
||||
this.fileHandlerService = fileHandlerService;
|
||||
this.cacheService = cacheService;
|
||||
this.otherFilePreview = otherFilePreview;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/onlinePreview")
|
||||
public String onlinePreview(String url, Model model, HttpServletRequest req) {
|
||||
String fileUrl = new String(Base64Utils.decodeFromString(url));
|
||||
String fileUrl;
|
||||
try {
|
||||
fileUrl = new String(Base64Utils.decodeFromString(url));
|
||||
} catch (Exception ex) {
|
||||
String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "url");
|
||||
return otherFilePreview.notSupportedFile(model, errorMsg);
|
||||
}
|
||||
FileAttribute fileAttribute = fileHandlerService.getFileAttribute(fileUrl, req);
|
||||
FilePreview filePreview = previewFactory.get(fileAttribute);
|
||||
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
|
||||
@ -54,11 +64,17 @@ public class OnlinePreviewController {
|
||||
|
||||
@RequestMapping(value = "/picturesPreview")
|
||||
public String picturesPreview(String urls, Model model, HttpServletRequest req) throws UnsupportedEncodingException {
|
||||
String fileUrls = new String(Base64Utils.decodeFromString(urls));
|
||||
String fileUrls;
|
||||
try {
|
||||
fileUrls = new String(Base64Utils.decodeFromString(urls));
|
||||
} catch (Exception ex) {
|
||||
String errorMsg = String.format(BASE64_DECODE_ERROR_MSG, "urls");
|
||||
return otherFilePreview.notSupportedFile(model, errorMsg);
|
||||
}
|
||||
logger.info("预览文件url:{},urls:{}", fileUrls, urls);
|
||||
// 抽取文件并返回文件列表
|
||||
String[] imgs = fileUrls.split("\\|");
|
||||
List<String> imgUrls = Arrays.asList(imgs);
|
||||
String[] images = fileUrls.split("\\|");
|
||||
List<String> imgUrls = Arrays.asList(images);
|
||||
model.addAttribute("imgUrls", imgUrls);
|
||||
|
||||
String currentUrl = req.getParameter("currentUrl");
|
||||
|
||||
7
server/src/main/log/README.txt
Normal file
7
server/src/main/log/README.txt
Normal file
@ -0,0 +1,7 @@
|
||||
README.txt
|
||||
log目录是用来存放kkFileView.log的,预览服务的运行情况最终都会反映到这个日志文件里,
|
||||
可以提供给开发、运维排查系统问题。如果通过kkFileView.log还无法定位问题所在,请你在寻求
|
||||
kk官方支持时,QQ群一 613025121、QQ群二 484680571。将此日志文件一并携带,并按照这个
|
||||
格式重命名日志文件 kkFileView-QQ昵称-时间日期.log。如:kkFileView-kl博主-2020-12-27.log 。
|
||||
所有收集的日志文件我们都会存档,供所有的kk用户作为排查案例使用,所以在你提供日志前,请
|
||||
先自行处理日志文件里的业务敏感内容。
|
||||
25473
server/src/main/resources/static/pdfjs/build/pdf.js
Normal file
25473
server/src/main/resources/static/pdfjs/build/pdf.js
Normal file
File diff suppressed because it is too large
Load Diff
1
server/src/main/resources/static/pdfjs/build/pdf.js.map
Normal file
1
server/src/main/resources/static/pdfjs/build/pdf.js.map
Normal file
File diff suppressed because one or more lines are too long
57878
server/src/main/resources/static/pdfjs/build/pdf.worker.js
vendored
Normal file
57878
server/src/main/resources/static/pdfjs/build/pdf.worker.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
server/src/main/resources/static/pdfjs/build/pdf.worker.js.map
vendored
Normal file
1
server/src/main/resources/static/pdfjs/build/pdf.worker.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -19,18 +19,17 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="panel-group container" id="accordion">
|
||||
<h1>文件预览项目接入和测试界面</h1>
|
||||
<div class="panel-group" id="accordion">
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion"
|
||||
href="#collapseOne">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
|
||||
接入说明
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseOne" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div>
|
||||
如果你的项目需要接入文件预览项目,达到对docx、excel、ppt、jpg等文件的预览效果,那么通过在你的项目中加入下面的代码就可以
|
||||
@ -49,7 +48,6 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
@ -59,12 +57,11 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseTwo" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div style="padding: 10px">
|
||||
<form enctype="multipart/form-data" id="fileUpload">
|
||||
<input type="file" name="file"/>
|
||||
<input type="button" id="btnsubmit" value=" 上 传 " />
|
||||
<input type="button" id="btnubmit" value=" 上 传 "/>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
@ -72,21 +69,18 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion"
|
||||
href="#collapseThree">
|
||||
更新记录
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
|
||||
发版记录
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapseThree" class="panel-collapse collapse in">
|
||||
<div class="panel-body">
|
||||
<div>
|
||||
2020年12月27日 :<br>
|
||||
2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设
|
||||
2020年年终大版本更新,架构全面设计,代码全面重构,代码质量全面提升,二次开发更便捷,欢迎拉源码品鉴,提issue、pr共同建设<br>
|
||||
1. 架构模块调整,大量的代码重构,代码质量提升N个等级,欢迎品鉴<br>
|
||||
2. 增强XML文件预览效果,新增XML文档数结构预览<br>
|
||||
3. 新增markdown文件预览支持,预览支持md渲染和源文本切换支持<br>
|
||||
@ -154,7 +148,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
2.项目github开源:<a href="https://github.com/kekingcn/kkFileView" target="_blank">https://github.com/kekingcn/kkFileView</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div id="comments"></div>
|
||||
</div>
|
||||
@ -190,7 +184,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
url: '${baseUrl}deleteFile?fileName=' + encodeURIComponent(fileName),
|
||||
success: function (data) {
|
||||
// 删除完成,刷新table
|
||||
if (1 == data.code) {
|
||||
if (1 === data.code) {
|
||||
alert(data.msg);
|
||||
} else {
|
||||
$('#table').bootstrapTable('refresh', {});
|
||||
@ -201,6 +195,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('#table').bootstrapTable({
|
||||
url: 'listFiles',
|
||||
@ -228,12 +223,12 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(bas
|
||||
$(".loading_container").css("height", height).show();
|
||||
}
|
||||
|
||||
$("#btnsubmit").click(function () {
|
||||
$("#btnSubmit").click(function () {
|
||||
showLoadingDiv();
|
||||
$("#fileUpload").ajaxSubmit({
|
||||
success: function (data) {
|
||||
// 上传完成,刷新table
|
||||
if (1 == data.code) {
|
||||
if (1 === data.code) {
|
||||
alert(data.msg);
|
||||
} else {
|
||||
$('#table').bootstrapTable('refresh', {});
|
||||
|
||||
Reference in New Issue
Block a user