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
5cad4aa9
Commit
5cad4aa9
authored
Mar 18, 2021
by
kl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文本预览转义处理
parent
2a61449c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
1 deletion
+4
-1
FileType.java
server/src/main/java/cn/keking/model/FileType.java
+1
-1
SimTextFilePreviewImpl.java
...n/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+3
-0
No files found.
server/src/main/java/cn/keking/model/FileType.java
View file @
5cad4aa9
...
@@ -31,7 +31,7 @@ public enum FileType {
...
@@ -31,7 +31,7 @@ public enum FileType {
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
[]
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
[]
CODES
=
{
"java"
,
"c"
,
"php"
,
"go"
,
"python"
,
"py"
,
"js"
,
"html"
,
"ftl"
,
"css"
,
"lua"
,
"sh"
,
"rb"
,
"h"
,
"cpp"
,
"cs"
,
"aspx"
,
"jsp"
};
private
static
final
String
[]
CODES
=
{
"java"
,
"c"
,
"php"
,
"go"
,
"python"
,
"py"
,
"js"
,
"html"
,
"ftl"
,
"css"
,
"lua"
,
"sh"
,
"rb"
,
"
yml"
,
"json"
,
"
h"
,
"cpp"
,
"cs"
,
"aspx"
,
"jsp"
};
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
<>();
...
...
server/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
View file @
5cad4aa9
...
@@ -9,9 +9,11 @@ import jodd.io.FileUtil;
...
@@ -9,9 +9,11 @@ import jodd.io.FileUtil;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.util.HtmlUtils
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
/**
/**
* Created by kl on 2018/1/17.
* Created by kl on 2018/1/17.
...
@@ -37,6 +39,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
...
@@ -37,6 +39,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
File
originFile
=
new
File
(
response
.
getContent
());
File
originFile
=
new
File
(
response
.
getContent
());
String
charset
=
KkFileUtils
.
getFileEncode
(
originFile
);
String
charset
=
KkFileUtils
.
getFileEncode
(
originFile
);
String
fileData
=
FileUtil
.
readString
(
originFile
,
charset
);
String
fileData
=
FileUtil
.
readString
(
originFile
,
charset
);
fileData
=
HtmlUtils
.
htmlEscape
(
fileData
,
StandardCharsets
.
UTF_8
.
name
());
model
.
addAttribute
(
"textData"
,
Base64
.
encodeBase64String
(
fileData
.
getBytes
()));
model
.
addAttribute
(
"textData"
,
Base64
.
encodeBase64String
(
fileData
.
getBytes
()));
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
return
otherFilePreview
.
notSupportedFile
(
model
,
fileAttribute
,
e
.
getLocalizedMessage
());
return
otherFilePreview
.
notSupportedFile
(
model
,
fileAttribute
,
e
.
getLocalizedMessage
());
...
...
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