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
b003a057
Commit
b003a057
authored
Aug 22, 2019
by
陈精华
Committed by
kl
Aug 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入是否启用缓存配置项
parent
98ec3d7d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
8 deletions
+27
-8
application.properties
jodconverter-web/src/main/conf/application.properties
+3
-0
ConfigConstants.java
...r-web/src/main/java/cn/keking/config/ConfigConstants.java
+9
-0
ConfigRefreshComponent.java
...rc/main/java/cn/keking/config/ConfigRefreshComponent.java
+4
-0
CompressFilePreviewImpl.java
.../java/cn/keking/service/impl/CompressFilePreviewImpl.java
+3
-2
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+8
-6
No files found.
jodconverter-web/src/main/conf/application.properties
View file @
b003a057
...
@@ -31,6 +31,9 @@ spring.http.multipart.max-file-size=100MB
...
@@ -31,6 +31,9 @@ spring.http.multipart.max-file-size=100MB
cache.clean
=
true
cache.clean
=
true
#######################################可在运行时动态配置#######################################
#######################################可在运行时动态配置#######################################
#是否启用缓存
cache.enabled
=
false
#文本类型,默认如下,可自定义添加
#文本类型,默认如下,可自定义添加
#simText = txt,html,xml,properties,md,java,py,c,cpp,sql
#simText = txt,html,xml,properties,md,java,py,c,cpp,sql
#多媒体类型,默认如下,可自定义添加
#多媒体类型,默认如下,可自定义添加
...
...
jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java
View file @
b003a057
...
@@ -14,6 +14,7 @@ import java.io.File;
...
@@ -14,6 +14,7 @@ import java.io.File;
@Component
@Component
public
class
ConfigConstants
{
public
class
ConfigConstants
{
private
static
Boolean
cacheEnabled
;
private
static
String
[]
simText
=
{};
private
static
String
[]
simText
=
{};
private
static
String
[]
media
=
{};
private
static
String
[]
media
=
{};
private
static
String
convertedFileCharset
;
private
static
String
convertedFileCharset
;
...
@@ -23,6 +24,14 @@ public class ConfigConstants {
...
@@ -23,6 +24,14 @@ public class ConfigConstants {
private
static
String
ftpControlEncoding
;
private
static
String
ftpControlEncoding
;
private
static
String
fileDir
=
OfficeUtils
.
getHomePath
()
+
File
.
separator
+
"file"
+
File
.
separator
;
private
static
String
fileDir
=
OfficeUtils
.
getHomePath
()
+
File
.
separator
+
"file"
+
File
.
separator
;
public
static
Boolean
isCacheEnabled
()
{
return
cacheEnabled
;
}
public
static
void
setCacheEnabled
(
Boolean
cacheEnabled
)
{
ConfigConstants
.
cacheEnabled
=
cacheEnabled
;
}
public
static
String
[]
getSimText
()
{
public
static
String
[]
getSimText
()
{
return
simText
;
return
simText
;
}
}
...
...
jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java
View file @
b003a057
...
@@ -22,6 +22,7 @@ public class ConfigRefreshComponent {
...
@@ -22,6 +22,7 @@ public class ConfigRefreshComponent {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ConfigRefreshComponent
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ConfigRefreshComponent
.
class
);
public
static
final
String
DEFAULT_CACHE_ENABLED
=
"true"
;
public
static
final
String
DEFAULT_TXT_TYPE
=
"txt,html,xml,properties,md,java,py,c,cpp,sql"
;
public
static
final
String
DEFAULT_TXT_TYPE
=
"txt,html,xml,properties,md,java,py,c,cpp,sql"
;
public
static
final
String
DEFAULT_MEDIA_TYPE
=
"mp3,wav,mp4,flv"
;
public
static
final
String
DEFAULT_MEDIA_TYPE
=
"mp3,wav,mp4,flv"
;
public
static
final
String
DEFAULT_CONVERTER_CHARSET
=
System
.
getProperty
(
"sun.jnu.encoding"
);
public
static
final
String
DEFAULT_CONVERTER_CHARSET
=
System
.
getProperty
(
"sun.jnu.encoding"
);
...
@@ -43,6 +44,7 @@ public class ConfigRefreshComponent {
...
@@ -43,6 +44,7 @@ public class ConfigRefreshComponent {
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
String
text
;
String
text
;
String
media
;
String
media
;
Boolean
cacheEnabled
;
String
[]
textArray
;
String
[]
textArray
;
String
[]
mediaArray
;
String
[]
mediaArray
;
String
convertedFileCharset
;
String
convertedFileCharset
;
...
@@ -55,6 +57,7 @@ public class ConfigRefreshComponent {
...
@@ -55,6 +57,7 @@ public class ConfigRefreshComponent {
FileReader
fileReader
=
new
FileReader
(
configFilePath
);
FileReader
fileReader
=
new
FileReader
(
configFilePath
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
properties
.
load
(
bufferedReader
);
properties
.
load
(
bufferedReader
);
cacheEnabled
=
new
Boolean
(
properties
.
getProperty
(
"cache.enabled"
,
DEFAULT_CACHE_ENABLED
));
text
=
properties
.
getProperty
(
"simText"
,
DEFAULT_TXT_TYPE
);
text
=
properties
.
getProperty
(
"simText"
,
DEFAULT_TXT_TYPE
);
media
=
properties
.
getProperty
(
"media"
,
DEFAULT_MEDIA_TYPE
);
media
=
properties
.
getProperty
(
"media"
,
DEFAULT_MEDIA_TYPE
);
convertedFileCharset
=
properties
.
getProperty
(
"converted.file.charset"
,
DEFAULT_CONVERTER_CHARSET
);
convertedFileCharset
=
properties
.
getProperty
(
"converted.file.charset"
,
DEFAULT_CONVERTER_CHARSET
);
...
@@ -64,6 +67,7 @@ public class ConfigRefreshComponent {
...
@@ -64,6 +67,7 @@ public class ConfigRefreshComponent {
ftpControlEncoding
=
properties
.
getProperty
(
"ftp.control.encoding"
,
DEFAULT_FTP_CONTROL_ENCODING
);
ftpControlEncoding
=
properties
.
getProperty
(
"ftp.control.encoding"
,
DEFAULT_FTP_CONTROL_ENCODING
);
textArray
=
text
.
split
(
","
);
textArray
=
text
.
split
(
","
);
mediaArray
=
media
.
split
(
","
);
mediaArray
=
media
.
split
(
","
);
ConfigConstants
.
setCacheEnabled
(
cacheEnabled
);
ConfigConstants
.
setSimText
(
textArray
);
ConfigConstants
.
setSimText
(
textArray
);
ConfigConstants
.
setMedia
(
mediaArray
);
ConfigConstants
.
setMedia
(
mediaArray
);
ConfigConstants
.
setConvertedFileCharset
(
convertedFileCharset
);
ConfigConstants
.
setConvertedFileCharset
(
convertedFileCharset
);
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/CompressFilePreviewImpl.java
View file @
b003a057
package
cn
.
keking
.
service
.
impl
;
package
cn
.
keking
.
service
.
impl
;
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
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
...
@@ -33,7 +34,7 @@ public class CompressFilePreviewImpl implements FilePreview{
...
@@ -33,7 +34,7 @@ public class CompressFilePreviewImpl implements FilePreview{
String
suffix
=
fileAttribute
.
getSuffix
();
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileTree
=
null
;
String
fileTree
=
null
;
// 判断文件名是否存在(redis缓存读取)
// 判断文件名是否存在(redis缓存读取)
if
(!
StringUtils
.
hasText
(
fileUtils
.
getConvertedFile
(
fileName
)))
{
if
(!
StringUtils
.
hasText
(
fileUtils
.
getConvertedFile
(
fileName
))
||
!
ConfigConstants
.
isCacheEnabled
()
)
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
...
@@ -48,7 +49,7 @@ public class CompressFilePreviewImpl implements FilePreview{
...
@@ -48,7 +49,7 @@ public class CompressFilePreviewImpl implements FilePreview{
}
else
if
(
"7z"
.
equalsIgnoreCase
(
suffix
))
{
}
else
if
(
"7z"
.
equalsIgnoreCase
(
suffix
))
{
fileTree
=
zipReader
.
read7zFile
(
filePath
,
fileName
);
fileTree
=
zipReader
.
read7zFile
(
filePath
,
fileName
);
}
}
if
(
fileTree
!=
null
&&
!
"null"
.
equals
(
fileTree
))
{
if
(
fileTree
!=
null
&&
!
"null"
.
equals
(
fileTree
)
&&
ConfigConstants
.
isCacheEnabled
()
)
{
fileUtils
.
addConvertedFile
(
fileName
,
fileTree
);
fileUtils
.
addConvertedFile
(
fileName
,
fileTree
);
}
}
}
else
{
}
else
{
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
b003a057
...
@@ -52,7 +52,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -52,7 +52,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
(
isHtml
?
"html"
:
"pdf"
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
(
isHtml
?
"html"
:
"pdf"
);
String
outFilePath
=
fileDir
+
pdfName
;
String
outFilePath
=
fileDir
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
))
{
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
()
)
{
String
filePath
=
fileDir
+
fileName
;
String
filePath
=
fileDir
+
fileName
;
if
(!
new
File
(
filePath
).
exists
())
{
if
(!
new
File
(
filePath
).
exists
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
...
@@ -69,12 +69,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -69,12 +69,14 @@ public class OfficeFilePreviewImpl implements FilePreview {
if
(
f
.
exists
())
{
if
(
f
.
exists
())
{
f
.
delete
();
f
.
delete
();
}
}
if
(
isHtml
)
{
if
(
ConfigConstants
.
isCacheEnabled
())
{
// 对转换后的文件进行操作(改变编码方式)
if
(
isHtml
)
{
fileUtils
.
doActionConvertedFile
(
outFilePath
);
// 对转换后的文件进行操作(改变编码方式)
fileUtils
.
doActionConvertedFile
(
outFilePath
);
}
// 加入缓存
fileUtils
.
addConvertedFile
(
pdfName
,
fileUtils
.
getRelativePath
(
outFilePath
));
}
}
// 加入缓存
fileUtils
.
addConvertedFile
(
pdfName
,
fileUtils
.
getRelativePath
(
outFilePath
));
}
}
}
}
if
(!
isHtml
&&
originUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
if
(!
isHtml
&&
originUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
...
...
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