提交 1f0e1d04 作者: ZhangJingKun

在线编辑 zhangjingkun

上级 4bd10ac4
......@@ -32,7 +32,11 @@ public class KnowInterceptor implements HandlerInterceptor {
// 返回true才会继续执行后续的Interceptor和Controller
// 返回false则取消当前请求
if (!request.getRequestURI().contains("test")) {
if (!request.getRequestURI().contains("js") && !request.getRequestURI().contains("css") //&& !request.getRequestURI().contains("edit")
&& !request.getRequestURI().contains("callback") && !request.getRequestURI().contains("download")
&& !request.getRequestURI().contains("favicon")
&& !request.getRequestURI().contains("api/file")
) {
String token = request.getHeader("X-Access-Token");
KbAuthorizedUserService userService = SpringContextUtils.getBean(KbAuthorizedUserService.class);
......
......@@ -21,7 +21,7 @@ public class DocumentConstants {
/**
* 文档文件下载接口地址
*/
public static final String OFFICE_API_DOC_FILE = "%s/download%s";
public static final String OFFICE_API_DOC_FILE = "%s/api/file/download%s";
/**
* 文档信息获取地址
*/
......@@ -29,7 +29,7 @@ public class DocumentConstants {
/**
* 编辑回调地址
*/
public static final String OFFICE_API_CALLBACK = "%s/callback";
public static final String OFFICE_API_CALLBACK = "%s/api/file/callback";
/**
* 预览地址
*/
......
......@@ -55,11 +55,12 @@ public class DocumentServiceImpl implements DocumentService {
@Override
public String buildDocument(String filePath, String fileName) {
if (StringUtils.isBlank(filePath)) {
String path = filesStorage + filePath;
if (StringUtils.isBlank(path)) {
throw new DocumentException(ErrorCodeEnum.DOC_FILE_NOT_EXISTS);
}
filePath = FilenameUtils.normalize(filePath);
String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(filePath));
path = FilenameUtils.normalize(path);
String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(path));
if (StringUtils.isBlank(fileType)) {
throw new DocumentException(ErrorCodeEnum.DOC_FILE_NO_EXTENSION);
}
......@@ -67,7 +68,7 @@ public class DocumentServiceImpl implements DocumentService {
if (StringUtils.isNotBlank(fileName) && !fileType.equalsIgnoreCase(FilenameUtils.getExtension(fileName))) {
throw new DocumentException(ErrorCodeEnum.DOC_FILE_EXTENSION_NOT_MATCH);
}
File docFile = new File(filesStorage+ filePath);
File docFile = new File(path);
// 校验文件实体
preFileCheck(docFile);
fileName = StringUtils.isNotBlank(fileName) ? fileName : docFile.getName();
......@@ -104,7 +105,7 @@ public class DocumentServiceImpl implements DocumentService {
}
// 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小)
// doc.setKey(documentKey);
doc.setUrl(fileUrl(doc.getTitle()));
doc.setUrl(fileUrl(doc.getTitle(),doc.getStorage()));
if (log.isDebugEnabled()) {
log.info(doc.toString());
}
......@@ -149,9 +150,9 @@ public class DocumentServiceImpl implements DocumentService {
* @param
* @return
*/
private String fileUrl(String filename) {
return String.format(DocumentConstants.OFFICE_API_DOC_FILE, getServerHost(), "?name="+filename);
// return "http://192.168.0.58:20053/download?name="+filename;
private String fileUrl(String filename,String filePath) {
return String.format(DocumentConstants.OFFICE_API_DOC_FILE, getServerHost(), "?fileName="+filename+"&filePath="+filePath);
// return "http://192.168.1.75:9088/download?filenamename="+filename+"&filePath="+filePath;
}
/**
......
......@@ -142,14 +142,13 @@ public class LocalFileServiceImpl implements ILocalFileService {
//edit
@Override
public String editDocFile(String fileName, String filePath, String userName, Model model) {
String path = filesStorage + filePath;
Document document = documentService.getDocument(documentService.buildDocument(path, fileName));
Document document = documentService.getDocument(documentService.buildDocument(filePath, fileName));
model.addAttribute("document", document);
// 如果该格式不支持编辑,则返回预览页面
if (!documentService.canEdit(document)) {
return "/demo";
}
model.addAttribute("documentEditParam", documentService.buildDocumentEditParam(userName, userName,fileName));
model.addAttribute("documentEditParam", documentService.buildDocumentEditParam(userName, userName,filePath));
return "/editor";
}
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
<title th:text="${document.title}"></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" th:href="@{/css/viewer.css}">
</head>
<body>
<div class="form">
<div id="iframeEditor"></div>
</div>
<script type="text/javascript" th:src="@{/js/jquery-1.8.2.js}"></script>
<script type="text/javascript" th:src="@{${documentServerApiJs}}"></script>
<script type="text/javascript" th:src="@{/js/editor.js}"></script>
<!-- 先通过 th:inline=“javascript” 添加到标签,这样js代码即可访问model中的属性 -->
<script th:inline="javascript">
// js 中可以通过“[[${xxx}]]” 格式获得实际的值
Editor.init([[${document}]], [[${documentEditParam}]]);
</script>
</body>
</html>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论