From 33fd0f8046b9e224ac834a1fed72d23f29826925 Mon Sep 17 00:00:00 2001 From: zhaojun1998 Date: Wed, 21 Aug 2019 16:25:18 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E4=BC=98=E5=8C=96=20URL=20=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../im/zhaojun/aliyun/service/AliyunService.java | 1 - .../im/zhaojun/common/controller/FileController.java | 12 ++---------- .../im/zhaojun/huawei/service/HuaweiService.java | 1 - src/main/resources/static/script/main.js | 8 ++++---- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/im/zhaojun/aliyun/service/AliyunService.java b/src/main/java/im/zhaojun/aliyun/service/AliyunService.java index 0bad8d8..42cd027 100644 --- a/src/main/java/im/zhaojun/aliyun/service/AliyunService.java +++ b/src/main/java/im/zhaojun/aliyun/service/AliyunService.java @@ -96,7 +96,6 @@ public class AliyunService implements FileService { @Override public String getDownloadUrl(String path) throws Exception { path = StringUtils.removeFirstSeparator(path); - path = URLDecoder.decode(path, "utf8"); if (isPrivate) { Date expirationDate = new Date(new Date().getTime() + timeout * 1000); diff --git a/src/main/java/im/zhaojun/common/controller/FileController.java b/src/main/java/im/zhaojun/common/controller/FileController.java index 158e9d3..082b0ab 100644 --- a/src/main/java/im/zhaojun/common/controller/FileController.java +++ b/src/main/java/im/zhaojun/common/controller/FileController.java @@ -5,23 +5,15 @@ import im.zhaojun.common.config.StorageTypeFactory; import im.zhaojun.common.enums.FileTypeEnum; import im.zhaojun.common.enums.StorageTypeEnum; import im.zhaojun.common.model.FileItem; -import im.zhaojun.common.model.ImageInfo; import im.zhaojun.common.model.ResultBean; import im.zhaojun.common.model.SiteConfig; import im.zhaojun.common.service.FileService; import im.zhaojun.common.service.SystemConfigService; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.PostConstruct; import javax.annotation.Resource; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Collections; import java.util.List; @@ -35,7 +27,7 @@ public class FileController { @GetMapping("/filelist") public ResultBean list(String path, String sortBy, boolean descending) throws Exception { - List fileItems = fileService.fileList(path); + List fileItems = fileService.fileList(URLUtil.decode(path)); // 排序, 先按照文件类型比较, 文件夹在前, 文件在后, 然后根据 sortBy 字段排序, 默认为升序; fileItems.sort((o1, o2) -> { @@ -72,7 +64,7 @@ public class FileController { */ @GetMapping("/downloadUrl") public ResultBean getDownloadUrl(String path) throws Exception { - return ResultBean.successData(fileService.getDownloadUrl(path)); + return ResultBean.successData(fileService.getDownloadUrl(URLUtil.decode(path))); } /** diff --git a/src/main/java/im/zhaojun/huawei/service/HuaweiService.java b/src/main/java/im/zhaojun/huawei/service/HuaweiService.java index 8098292..499bb56 100644 --- a/src/main/java/im/zhaojun/huawei/service/HuaweiService.java +++ b/src/main/java/im/zhaojun/huawei/service/HuaweiService.java @@ -96,7 +96,6 @@ public class HuaweiService implements FileService { @Override public String getDownloadUrl(String path) throws Exception { path = StringUtils.removeFirstSeparator(path); - path = URLDecoder.decode(path, "utf8"); TemporarySignatureRequest req = new TemporarySignatureRequest(HttpMethodEnum.GET, timeout); req.setBucketName(bucketName); req.setObjectKey(path); diff --git a/src/main/resources/static/script/main.js b/src/main/resources/static/script/main.js index f8dc88c..5f97cd9 100644 --- a/src/main/resources/static/script/main.js +++ b/src/main/resources/static/script/main.js @@ -89,7 +89,7 @@ function listObjects(path, sortBy, descending) { type: 'GET', url: 'filelist', data: { - path: path, + path: encodeURI(decodeURI(path)), // 先解码, 再编码, 防止重复编码 sortBy: sortBy, descending: descending }, @@ -130,7 +130,7 @@ function getDownloadUrl(path) { type: 'GET', url: 'downloadUrl', data: { - path: path + path: encodeURI(decodeURI(path)) }, async: false, success: function (data) { @@ -149,7 +149,7 @@ function getImageInfo(url) { type: 'GET', url: 'getImageInfo', data: { - url: encodeURI(url) + url: encodeURI(decodeURI(url)) }, async: false, success: function (data) { @@ -440,7 +440,7 @@ function openText(fileType, fileName, path) { content: '
' }); - $.get('/getContent', {path: path}, function (result) { + $.get('/getContent', {path: encodeURI(decodeURI(path))}, function (result) { var text = result.data; var markdownContent = $("#markdown-content"); var textContent = $("#text-content");