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
376a9077
Commit
376a9077
authored
Feb 08, 2021
by
kl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增 tiff 、tif 图像文件格式预览支持
parent
4f4e7585
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
35 deletions
+67
-35
application.properties
server/src/main/config/application.properties
+5
-7
freemarker_implicit.ftl
server/src/main/config/freemarker_implicit.ftl
+1
-0
FileType.java
server/src/main/java/cn/keking/model/FileType.java
+29
-24
CompressFileReader.java
...r/src/main/java/cn/keking/service/CompressFileReader.java
+3
-3
FileConvertQueueTask.java
...src/main/java/cn/keking/service/FileConvertQueueTask.java
+1
-1
FilePreview.java
server/src/main/java/cn/keking/service/FilePreview.java
+1
-0
TiffFilePreviewImpl.java
...main/java/cn/keking/service/impl/TiffFilePreviewImpl.java
+27
-0
tiff.min.js
server/src/main/resources/static/js/tiff.min.js
+0
-0
tiff.ftl
server/src/main/resources/web/tiff.ftl
+0
-0
No files found.
server/src/main/config/application.properties
View file @
376a9077
#######################################不可动态配置,需要重启生效#######################################
#######################################不可动态配置,需要重启生效#######################################
server.port
=
${KK_SERVER_PORT:8012}
server.port
=
${KK_SERVER_PORT:8012}
server.context-path
=
${KK_CONTEXT_PATH:/}
server.servlet.context-path
=
${KK_CONTEXT_PATH:/}
spring.http.encoding.charset
=
utf8
server.servlet.encoding.charset
=
utf-8
#文件上传限制
spring.servlet.multipart.max-file-size
=
500MB
spring.servlet.multipart.max-request-size
=
500MB
## Freemarker 配置
## Freemarker 配置
spring.freemarker.template-loader-path
=
classpath:/web/
spring.freemarker.template-loader-path
=
classpath:/web/
spring.freemarker.cache
=
false
spring.freemarker.cache
=
false
...
@@ -13,11 +16,6 @@ spring.freemarker.expose-session-attributes = true
...
@@ -13,11 +16,6 @@ spring.freemarker.expose-session-attributes = true
spring.freemarker.request-context-attribute
=
request
spring.freemarker.request-context-attribute
=
request
spring.freemarker.suffix
=
.ftl
spring.freemarker.suffix
=
.ftl
server.tomcat.uri-encoding
=
UTF-8
#文件上传限制
spring.http.multipart.max-request-size
=
500MB
spring.http.multipart.max-file-size
=
500MB
#文件资源路径(默认为打包根路径下的file目录下)
#文件资源路径(默认为打包根路径下的file目录下)
#file.dir = D:\\kkFileview\\
#file.dir = D:\\kkFileview\\
file.dir
=
${KK_FILE_DIR:default}
file.dir
=
${KK_FILE_DIR:default}
...
...
server/src/main/config/freemarker_implicit.ftl
View file @
376a9077
[#ftl]
[#ftl]
[#-- @implicitly included --]
[#-- @implicitly included --]
[#-- @ftlvariable name="currentUrl" type="java.lang.String" --]
[#-- @ftlvariable name="file" type="cn.keking.model.FileAttribute" --]
[#-- @ftlvariable name="file" type="cn.keking.model.FileAttribute" --]
[#-- @ftlvariable name="fileName" type="java.lang.String" --]
[#-- @ftlvariable name="fileName" type="java.lang.String" --]
[#-- @ftlvariable name="fileTree" type="java.lang.String" --]
[#-- @ftlvariable name="fileTree" type="java.lang.String" --]
...
...
server/src/main/java/cn/keking/model/FileType.java
View file @
376a9077
...
@@ -11,52 +11,57 @@ import java.util.Map;
...
@@ -11,52 +11,57 @@ import java.util.Map;
*/
*/
public
enum
FileType
{
public
enum
FileType
{
picture
(
"pictureFilePreviewImpl"
),
PICTURE
(
"pictureFilePreviewImpl"
),
compress
(
"compressFilePreviewImpl"
),
COMPRESS
(
"compressFilePreviewImpl"
),
office
(
"officeFilePreviewImpl"
),
OFFICE
(
"officeFilePreviewImpl"
),
simText
(
"simTextFilePreviewImpl"
),
SIMTEXT
(
"simTextFilePreviewImpl"
),
pdf
(
"pdfFilePreviewImpl"
),
PDF
(
"pdfFilePreviewImpl"
),
other
(
"otherFilePreviewImpl"
),
OTHER
(
"otherFilePreviewImpl"
),
media
(
"mediaFilePreviewImpl"
),
MEDIA
(
"mediaFilePreviewImpl"
),
markdown
(
"markdownFilePreviewImpl"
),
MARKDOWN
(
"markdownFilePreviewImpl"
),
xml
(
"xmlFilePreviewImpl"
),
XML
(
"xmlFilePreviewImpl"
),
flv
(
"flvFilePreviewImpl"
),
FLV
(
"flvFilePreviewImpl"
),
cad
(
"cadFilePreviewImpl"
);
CAD
(
"cadFilePreviewImpl"
),
TIFF
(
"tiffFilePreviewImpl"
);
private
static
final
String
[]
OFFICE_TYPES
=
{
"docx"
,
"doc"
,
"xls"
,
"xlsx"
,
"ppt"
,
"pptx"
};
private
static
final
String
[]
OFFICE_TYPES
=
{
"docx"
,
"doc"
,
"xls"
,
"xlsx"
,
"ppt"
,
"pptx"
};
private
static
final
String
[]
PICTURE_TYPES
=
{
"jpg"
,
"jpeg"
,
"png"
,
"gif"
,
"bmp"
,
"ico"
,
"raw"
};
private
static
final
String
[]
PICTURE_TYPES
=
{
"jpg"
,
"jpeg"
,
"png"
,
"gif"
,
"bmp"
,
"ico"
,
"raw"
};
private
static
final
String
[]
ARCHIVE_TYPES
=
{
"rar"
,
"zip"
,
"jar"
,
"7-zip"
,
"tar"
,
"gzip"
,
"7z"
};
private
static
final
String
[]
ARCHIVE_TYPES
=
{
"rar"
,
"zip"
,
"jar"
,
"7-zip"
,
"tar"
,
"gzip"
,
"7z"
};
private
static
final
String
[]
TIFF_TYPES
=
{
"tif"
,
"tiff"
};
private
static
final
String
[]
SSIM_TEXT_TYPES
=
ConfigConstants
.
getSimText
();
private
static
final
String
[]
SSIM_TEXT_TYPES
=
ConfigConstants
.
getSimText
();
private
static
final
String
[]
MEDIA_TYPES
=
ConfigConstants
.
getMedia
();
private
static
final
String
[]
MEDIA_TYPES
=
ConfigConstants
.
getMedia
();
private
static
final
Map
<
String
,
FileType
>
FILE_TYPE_MAPPER
=
new
HashMap
<>();
private
static
final
Map
<
String
,
FileType
>
FILE_TYPE_MAPPER
=
new
HashMap
<>();
static
{
static
{
for
(
String
office
:
OFFICE_TYPES
)
{
for
(
String
office
:
OFFICE_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
office
,
FileType
.
office
);
FILE_TYPE_MAPPER
.
put
(
office
,
FileType
.
OFFICE
);
}
}
for
(
String
picture
:
PICTURE_TYPES
)
{
for
(
String
picture
:
PICTURE_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
picture
,
FileType
.
picture
);
FILE_TYPE_MAPPER
.
put
(
picture
,
FileType
.
PICTURE
);
}
}
for
(
String
archive
:
ARCHIVE_TYPES
)
{
for
(
String
archive
:
ARCHIVE_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
archive
,
FileType
.
compress
);
FILE_TYPE_MAPPER
.
put
(
archive
,
FileType
.
COMPRESS
);
}
}
for
(
String
text
:
SSIM_TEXT_TYPES
)
{
for
(
String
text
:
SSIM_TEXT_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
text
,
FileType
.
simText
);
FILE_TYPE_MAPPER
.
put
(
text
,
FileType
.
SIMTEXT
);
}
}
for
(
String
media
:
MEDIA_TYPES
)
{
for
(
String
media
:
MEDIA_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
media
,
FileType
.
media
);
FILE_TYPE_MAPPER
.
put
(
media
,
FileType
.
MEDIA
);
}
}
FILE_TYPE_MAPPER
.
put
(
"md"
,
FileType
.
markdown
);
for
(
String
tif
:
TIFF_TYPES
)
{
FILE_TYPE_MAPPER
.
put
(
"xml"
,
FileType
.
xml
);
FILE_TYPE_MAPPER
.
put
(
tif
,
FileType
.
TIFF
);
FILE_TYPE_MAPPER
.
put
(
"pdf"
,
FileType
.
pdf
);
}
FILE_TYPE_MAPPER
.
put
(
"dwg"
,
FileType
.
cad
);
FILE_TYPE_MAPPER
.
put
(
"md"
,
FileType
.
MARKDOWN
);
FILE_TYPE_MAPPER
.
put
(
"flv"
,
FileType
.
flv
);
FILE_TYPE_MAPPER
.
put
(
"xml"
,
FileType
.
XML
);
FILE_TYPE_MAPPER
.
put
(
"pdf"
,
FileType
.
PDF
);
FILE_TYPE_MAPPER
.
put
(
"dwg"
,
FileType
.
CAD
);
FILE_TYPE_MAPPER
.
put
(
"flv"
,
FileType
.
FLV
);
}
}
private
static
FileType
to
(
String
fileType
){
private
static
FileType
to
(
String
fileType
)
{
return
FILE_TYPE_MAPPER
.
getOrDefault
(
fileType
,
other
);
return
FILE_TYPE_MAPPER
.
getOrDefault
(
fileType
,
OTHER
);
}
}
/**
/**
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
*
*
...
...
server/src/main/java/cn/keking/service/CompressFileReader.java
View file @
376a9077
...
@@ -68,7 +68,7 @@ public class CompressFileReader {
...
@@ -68,7 +68,7 @@ public class CompressFileReader {
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
PICTURE
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
...
@@ -121,7 +121,7 @@ public class CompressFileReader {
...
@@ -121,7 +121,7 @@ public class CompressFileReader {
}
}
String
parentName
=
getLast2FileName
(
fullName
,
"\\"
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
"\\"
,
archiveFileName
);
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
PICTURE
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
...
@@ -164,7 +164,7 @@ public class CompressFileReader {
...
@@ -164,7 +164,7 @@ public class CompressFileReader {
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
String
parentName
=
getLast2FileName
(
fullName
,
archiveSeparator
,
archiveFileName
);
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
parentName
=
(
level
-
1
)
+
"_"
+
parentName
;
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
FileType
type
=
FileType
.
typeFromUrl
(
childName
);
if
(
type
.
equals
(
FileType
.
picture
))
{
//添加图片文件到图片列表
if
(
type
.
equals
(
FileType
.
PICTURE
))
{
//添加图片文件到图片列表
imgUrls
.
add
(
baseUrl
+
childName
);
imgUrls
.
add
(
baseUrl
+
childName
);
}
}
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
FileNode
node
=
new
FileNode
(
originName
,
childName
,
parentName
,
new
ArrayList
<>(),
directory
,
fileKey
);
...
...
server/src/main/java/cn/keking/service/FileConvertQueueTask.java
View file @
376a9077
...
@@ -62,7 +62,7 @@ public class FileConvertQueueTask {
...
@@ -62,7 +62,7 @@ public class FileConvertQueueTask {
FileAttribute
fileAttribute
=
fileHandlerService
.
getFileAttribute
(
url
,
null
);
FileAttribute
fileAttribute
=
fileHandlerService
.
getFileAttribute
(
url
,
null
);
FileType
fileType
=
fileAttribute
.
getType
();
FileType
fileType
=
fileAttribute
.
getType
();
logger
.
info
(
"正在处理预览转换任务,url:{},预览类型:{}"
,
url
,
fileType
);
logger
.
info
(
"正在处理预览转换任务,url:{},预览类型:{}"
,
url
,
fileType
);
if
(
fileType
.
equals
(
FileType
.
compress
)
||
fileType
.
equals
(
FileType
.
office
)
||
fileType
.
equals
(
FileType
.
cad
))
{
if
(
fileType
.
equals
(
FileType
.
COMPRESS
)
||
fileType
.
equals
(
FileType
.
OFFICE
)
||
fileType
.
equals
(
FileType
.
CAD
))
{
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
filePreview
.
filePreviewHandle
(
url
,
new
ExtendedModelMap
(),
fileAttribute
);
filePreview
.
filePreviewHandle
(
url
,
new
ExtendedModelMap
(),
fileAttribute
);
}
else
{
}
else
{
...
...
server/src/main/java/cn/keking/service/FilePreview.java
View file @
376a9077
...
@@ -14,6 +14,7 @@ public interface FilePreview {
...
@@ -14,6 +14,7 @@ public interface FilePreview {
String
COMPRESS_FILE_PREVIEW_PAGE
=
"compress"
;
String
COMPRESS_FILE_PREVIEW_PAGE
=
"compress"
;
String
MEDIA_FILE_PREVIEW_PAGE
=
"media"
;
String
MEDIA_FILE_PREVIEW_PAGE
=
"media"
;
String
PICTURE_FILE_PREVIEW_PAGE
=
"picture"
;
String
PICTURE_FILE_PREVIEW_PAGE
=
"picture"
;
String
TIFF_FILE_PREVIEW_PAGE
=
"tiff"
;
String
OFFICE_PICTURE_FILE_PREVIEW_PAGE
=
"officePicture"
;
String
OFFICE_PICTURE_FILE_PREVIEW_PAGE
=
"officePicture"
;
String
TXT_FILE_PREVIEW_PAGE
=
"txt"
;
String
TXT_FILE_PREVIEW_PAGE
=
"txt"
;
String
EXEL_FILE_PREVIEW_PAGE
=
"html"
;
String
EXEL_FILE_PREVIEW_PAGE
=
"html"
;
...
...
server/src/main/java/cn/keking/service/impl/TiffFilePreviewImpl.java
0 → 100644
View file @
376a9077
package
cn
.
keking
.
service
.
impl
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.service.FilePreview
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
/**
* tiff 图片文件处理
* @author kl (http://kailing.pub)
* @since 2021/2/8
*/
@Service
public
class
TiffFilePreviewImpl
implements
FilePreview
{
private
final
PictureFilePreviewImpl
pictureFilePreview
;
public
TiffFilePreviewImpl
(
PictureFilePreviewImpl
pictureFilePreview
)
{
this
.
pictureFilePreview
=
pictureFilePreview
;
}
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
pictureFilePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
return
TIFF_FILE_PREVIEW_PAGE
;
}
}
server/src/main/resources/static/js/tiff.min.js
0 → 100644
View file @
376a9077
This source diff could not be displayed because it is too large. You can
view the blob
instead.
server/src/main/resources/web/tiff.ftl
0 → 100644
View file @
376a9077
This diff is collapsed.
Click to expand it.
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