Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
K
know-base
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
张京坤
know-base
Commits
1f0e1d04
提交
1f0e1d04
authored
1月 15, 2024
作者:
ZhangJingKun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
在线编辑 zhangjingkun
上级
4bd10ac4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
18 行增加
和
36 行删除
+18
-36
KnowInterceptor.java
...com/zzsn/knowbase/config/interceptor/KnowInterceptor.java
+5
-1
DocumentConstants.java
...in/java/com/zzsn/knowbase/constant/DocumentConstants.java
+2
-2
DocumentServiceImpl.java
...a/com/zzsn/knowbase/service/impl/DocumentServiceImpl.java
+9
-8
LocalFileServiceImpl.java
.../com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
+2
-3
editor.html
src/main/resources/templates/editor.html
+0
-22
没有找到文件。
src/main/java/com/zzsn/knowbase/config/interceptor/KnowInterceptor.java
浏览文件 @
1f0e1d04
...
...
@@ -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
);
...
...
src/main/java/com/zzsn/knowbase/constant/DocumentConstants.java
浏览文件 @
1f0e1d04
...
...
@@ -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"
;
/**
* 预览地址
*/
...
...
src/main/java/com/zzsn/knowbase/service/impl/DocumentServiceImpl.java
浏览文件 @
1f0e1d04
...
...
@@ -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
(
fileP
ath
);
String
fileType
=
StringUtils
.
lowerCase
(
FilenameUtils
.
getExtension
(
fileP
ath
));
path
=
FilenameUtils
.
normalize
(
p
ath
);
String
fileType
=
StringUtils
.
lowerCase
(
FilenameUtils
.
getExtension
(
p
ath
));
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
+
fileP
ath
);
File
docFile
=
new
File
(
p
ath
);
// 校验文件实体
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
;
}
/**
...
...
src/main/java/com/zzsn/knowbase/service/impl/LocalFileServiceImpl.java
浏览文件 @
1f0e1d04
...
...
@@ -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
,
file
Name
));
model
.
addAttribute
(
"documentEditParam"
,
documentService
.
buildDocumentEditParam
(
userName
,
userName
,
file
Path
));
return
"/editor"
;
}
...
...
src/main/resources/templates/editor.html
deleted
100644 → 0
浏览文件 @
4bd10ac4
<!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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论