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
ef46e2c5
Commit
ef46e2c5
authored
Dec 28, 2020
by
kl
Committed by
kl
Dec 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增强url base64解码失败时的提示信息
parent
0a3c03f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
9 deletions
+45
-9
OtherFilePreviewImpl.java
...ain/java/cn/keking/service/impl/OtherFilePreviewImpl.java
+22
-2
OnlinePreviewController.java
...ava/cn/keking/web/controller/OnlinePreviewController.java
+23
-7
No files found.
server/src/main/java/cn/keking/service/impl/OtherFilePreviewImpl.java
View file @
ef46e2c5
...
...
@@ -15,7 +15,7 @@ public class OtherFilePreviewImpl implements FilePreview {
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
return
this
.
notSupportedFile
(
model
,
fileAttribute
,
"系统还不支持该格式文件的在线预览"
);
return
this
.
notSupportedFile
(
model
,
fileAttribute
,
"系统还不支持该格式文件的在线预览"
);
}
/**
...
...
@@ -24,8 +24,28 @@ public class OtherFilePreviewImpl implements FilePreview {
* @return 页面
*/
public
String
notSupportedFile
(
Model
model
,
FileAttribute
fileAttribute
,
String
errMsg
)
{
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
this
.
notSupportedFile
(
model
,
fileAttribute
.
getSuffix
(),
errMsg
);
}
/**
* 通用的预览失败,导向到不支持的文件响应页面
*
* @return 页面
*/
public
String
notSupportedFile
(
Model
model
,
String
errMsg
)
{
return
this
.
notSupportedFile
(
model
,
"未知"
,
errMsg
);
}
/**
* 通用的预览失败,导向到不支持的文件响应页面
*
* @return 页面
*/
public
String
notSupportedFile
(
Model
model
,
String
fileType
,
String
errMsg
)
{
model
.
addAttribute
(
"fileType"
,
fileType
);
model
.
addAttribute
(
"msg"
,
errMsg
);
return
NOT_SUPPORTED_FILE_PAGE
;
}
}
server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
View file @
ef46e2c5
...
...
@@ -5,6 +5,7 @@ import cn.keking.service.FilePreview;
import
cn.keking.service.FilePreviewFactory
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.service.impl.OtherFilePreviewImpl
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.service.FileHandlerService
;
import
org.slf4j.Logger
;
...
...
@@ -31,21 +32,30 @@ import static cn.keking.service.FilePreview.PICTURE_FILE_PREVIEW_PAGE;
@Controller
public
class
OnlinePreviewController
{
public
static
final
String
BASE64_DECODE_ERROR_MSG
=
"Base64解码失败,请检查你的 %s 是否采用 Base64 + urlEncode 双重编码了!"
;
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
OnlinePreviewController
.
class
);
private
final
FilePreviewFactory
previewFactory
;
private
final
CacheService
cacheService
;
private
final
FileHandlerService
fileHandlerService
;
private
final
OtherFilePreviewImpl
otherFilePreview
;
public
OnlinePreviewController
(
FilePreviewFactory
filePreviewFactory
,
FileHandlerService
fileHandlerService
,
CacheService
cacheService
)
{
public
OnlinePreviewController
(
FilePreviewFactory
filePreviewFactory
,
FileHandlerService
fileHandlerService
,
CacheService
cacheService
,
OtherFilePreviewImpl
otherFilePreview
)
{
this
.
previewFactory
=
filePreviewFactory
;
this
.
fileHandlerService
=
fileHandlerService
;
this
.
cacheService
=
cacheService
;
this
.
otherFilePreview
=
otherFilePreview
;
}
@RequestMapping
(
value
=
"/onlinePreview"
)
public
String
onlinePreview
(
String
url
,
Model
model
,
HttpServletRequest
req
)
{
String
fileUrl
=
new
String
(
Base64Utils
.
decodeFromString
(
url
));
String
fileUrl
;
try
{
fileUrl
=
new
String
(
Base64Utils
.
decodeFromString
(
url
));
}
catch
(
Exception
ex
)
{
String
errorMsg
=
String
.
format
(
BASE64_DECODE_ERROR_MSG
,
"url"
);
return
otherFilePreview
.
notSupportedFile
(
model
,
errorMsg
);
}
FileAttribute
fileAttribute
=
fileHandlerService
.
getFileAttribute
(
fileUrl
,
req
);
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
logger
.
info
(
"预览文件url:{},previewType:{}"
,
fileUrl
,
fileAttribute
.
getType
());
...
...
@@ -54,18 +64,24 @@ public class OnlinePreviewController {
@RequestMapping
(
value
=
"/picturesPreview"
)
public
String
picturesPreview
(
String
urls
,
Model
model
,
HttpServletRequest
req
)
throws
UnsupportedEncodingException
{
String
fileUrls
=
new
String
(
Base64Utils
.
decodeFromString
(
urls
));
String
fileUrls
;
try
{
fileUrls
=
new
String
(
Base64Utils
.
decodeFromString
(
urls
));
}
catch
(
Exception
ex
)
{
String
errorMsg
=
String
.
format
(
BASE64_DECODE_ERROR_MSG
,
"urls"
);
return
otherFilePreview
.
notSupportedFile
(
model
,
errorMsg
);
}
logger
.
info
(
"预览文件url:{},urls:{}"
,
fileUrls
,
urls
);
// 抽取文件并返回文件列表
String
[]
im
g
s
=
fileUrls
.
split
(
"\\|"
);
List
<
String
>
imgUrls
=
Arrays
.
asList
(
im
g
s
);
String
[]
im
age
s
=
fileUrls
.
split
(
"\\|"
);
List
<
String
>
imgUrls
=
Arrays
.
asList
(
im
age
s
);
model
.
addAttribute
(
"imgUrls"
,
imgUrls
);
String
currentUrl
=
req
.
getParameter
(
"currentUrl"
);
if
(
StringUtils
.
hasText
(
currentUrl
))
{
if
(
StringUtils
.
hasText
(
currentUrl
))
{
String
decodedCurrentUrl
=
new
String
(
Base64Utils
.
decodeFromString
(
currentUrl
));
model
.
addAttribute
(
"currentUrl"
,
decodedCurrentUrl
);
}
else
{
}
else
{
model
.
addAttribute
(
"currentUrl"
,
imgUrls
.
get
(
0
));
}
return
PICTURE_FILE_PREVIEW_PAGE
;
...
...
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