Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
梁杰芳
slm-fileview
Commits
c7318c2b
Commit
c7318c2b
authored
May 19, 2020
by
陈精华
Committed by
kl
May 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:PDF文件下载缓存
parent
c16116c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
14 deletions
+29
-14
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+28
-13
index.ftl
jodconverter-web/src/main/resources/web/index.ftl
+1
-1
No files found.
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
c7318c2b
...
...
@@ -26,6 +26,8 @@ public class PdfFilePreviewImpl implements FilePreview {
private
final
DownloadUtils
downloadUtils
;
private
static
final
String
FILE_DIR
=
ConfigConstants
.
getFileDir
();
public
PdfFilePreviewImpl
(
FileUtils
fileUtils
,
PdfUtils
pdfUtils
,
DownloadUtils
downloadUtils
)
{
...
...
@@ -41,16 +43,22 @@ public class PdfFilePreviewImpl implements FilePreview {
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
baseUrl
=
BaseUrlFilter
.
getBaseUrl
();
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
if
(
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OfficeFilePreviewImpl
.
OFFICE_PREVIEW_TYPE_ALL_IMAGES
.
equals
(
officePreviewType
))
{
//当文件不存在时,就去下载
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
outFilePath
=
response
.
getContent
();
if
(
ConfigConstants
.
isCacheEnabled
())
{
// 加入缓存
fileUtils
.
addConvertedFile
(
pdfName
,
fileUtils
.
getRelativePath
(
outFilePath
));
}
}
outFilePath
=
response
.
getContent
();
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
...
...
@@ -67,13 +75,20 @@ public class PdfFilePreviewImpl implements FilePreview {
}
else
{
// 不是http开头,浏览器不能直接访问,需下载到本地
if
(
url
!=
null
&&
!
url
.
toLowerCase
().
startsWith
(
"http"
))
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
pdfName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
else
{
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
pdfName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"pdfUrl"
,
fileUtils
.
getRelativePath
(
response
.
getContent
()));
if
(
ConfigConstants
.
isCacheEnabled
())
{
// 加入缓存
fileUtils
.
addConvertedFile
(
pdfName
,
fileUtils
.
getRelativePath
(
outFilePath
));
}
}
else
{
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
}
}
else
{
model
.
addAttribute
(
"pdfUrl"
,
url
);
...
...
jodconverter-web/src/main/resources/web/index.ftl
View file @
c7318c2b
...
...
@@ -195,7 +195,7 @@ window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(fil
}).
on
(
'pre-body.bs.table'
,
function
(
e
,
data
)
{
// 每个data添加一列用来操作
$
(
data
).
each
(
function
(
index
,
item
)
{
item
.
action
=
"<a class='btn btn-default' target='_blank' href='${baseUrl}onlinePreview?url="
+
encodeURIComponent
(
'${baseUrl}'
+
encodeURI
(
item
.
fileName
)
)
+
"'>预览</a>"
+
item
.
action
=
"<a class='btn btn-default' target='_blank' href='${baseUrl}onlinePreview?url="
+
encodeURIComponent
(
'${baseUrl}'
+
item
.
fileName
)
+
"'>预览</a>"
+
"<a class='btn btn-default' href='javascript:void(0);' onclick='deleteFile(
\"
"
+
item
.
fileName
+
"
\"
)'>删除</a>"
;
});
return
data
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment