From ba0cb8273a438a4507155340b0a37b3885befd19 Mon Sep 17 00:00:00 2001 From: "20932067@zju.edu.cn" Date: Fri, 19 Feb 2021 15:10:44 +0800 Subject: [PATCH] =?UTF-8?q?ftp=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hchyun-ui/src/api/system/download.js | 18 ++++---- hchyun-ui/src/views/system/file/index.vue | 5 +-- .../controller/common/CommonController.java | 6 +-- .../hchyun/common/utils/file/FileUtils.java | 1 + .../impl/SameUrlDataInterceptor.java | 41 +++++++------------ .../filter/JwtAuthenticationTokenFilter.java | 1 + 6 files changed, 30 insertions(+), 42 deletions(-) diff --git a/hchyun-ui/src/api/system/download.js b/hchyun-ui/src/api/system/download.js index c5a6040..91e19ba 100644 --- a/hchyun-ui/src/api/system/download.js +++ b/hchyun-ui/src/api/system/download.js @@ -1,14 +1,12 @@ import axios from "axios"; import {getToken} from "@/utils/auth"; -export function downloadFile(fileId){ - axios({ - method:'get', - url:process.env.VUE_APP_BASE_API+'/system/file/download/'+fileId, - headers:{ - token:'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 - } - }).then(res=>{ - return res; - }) +export function downloadFile(fileId) { + return axios({ + method: 'get', + url: process.env.VUE_APP_BASE_API + '/system/file/download/' + fileId, + headers: { + token: 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 + } + }) } diff --git a/hchyun-ui/src/views/system/file/index.vue b/hchyun-ui/src/views/system/file/index.vue index 29d356f..08fe9e3 100644 --- a/hchyun-ui/src/views/system/file/index.vue +++ b/hchyun-ui/src/views/system/file/index.vue @@ -342,10 +342,9 @@ export default { cancelButtonText: "取消", type: "warning" }).then(function (){ - return downloadFile(row.fileId) + return downloadFile(row.fileId) }).then(res =>{ - console.log(res) - // this.download(data.msg); + this.download(res.data.msg); }) }, // 表单重置 diff --git a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java index 08113e9..59875c9 100644 --- a/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java +++ b/hchyun/hchyun-admin/src/main/java/com/hchyun/web/controller/common/CommonController.java @@ -39,9 +39,9 @@ public class CommonController { @GetMapping("common/download") public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { try { - if (!FileUtils.isValidFilename(fileName)) { - throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 " , fileName)); - } +// if (!FileUtils.isValidFilename(fileName)) { +// throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 " , fileName)); +// } String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String filePath = HchYunConfig.getDownloadPath() + fileName; diff --git a/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUtils.java b/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUtils.java index 1067a1c..162638b 100644 --- a/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUtils.java +++ b/hchyun/hchyun-common/src/main/java/com/hchyun/common/utils/file/FileUtils.java @@ -68,6 +68,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils { File file = new File(filePath); // 路径为文件且不为空则进行删除 if (file.isFile() && file.exists()) { + System.gc(); file.delete(); flag = true; } diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/interceptor/impl/SameUrlDataInterceptor.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/interceptor/impl/SameUrlDataInterceptor.java index 5e3ff88..2219808 100644 --- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/interceptor/impl/SameUrlDataInterceptor.java +++ b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -18,12 +19,11 @@ import com.hchyun.framework.interceptor.RepeatSubmitInterceptor; /** * 判断请求url和数据是否和上一次相同, * 如果和上次相同,则是重复提交表单。 有效时间为10秒内。 - * + * * @author hchyun */ @Component -public class SameUrlDataInterceptor extends RepeatSubmitInterceptor -{ +public class SameUrlDataInterceptor extends RepeatSubmitInterceptor { public final String REPEAT_PARAMS = "repeatParams"; public final String REPEAT_TIME = "repeatTime"; @@ -37,30 +37,26 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor /** * 间隔时间,单位:秒 默认10秒 - * + *

* 两次相同参数的请求,如果间隔时间大于该参数,系统不会认定为重复提交的数据 */ private int intervalTime = 10; - public void setIntervalTime(int intervalTime) - { + public void setIntervalTime(int intervalTime) { this.intervalTime = intervalTime; } @SuppressWarnings("unchecked") @Override - public boolean isRepeatSubmit(HttpServletRequest request) - { + public boolean isRepeatSubmit(HttpServletRequest request) { String nowParams = ""; - if (request instanceof RepeatedlyRequestWrapper) - { + if (request instanceof RepeatedlyRequestWrapper) { RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; nowParams = HttpHelper.getBodyString(repeatedlyRequest); } // body参数为空,获取Parameter的数据 - if (StringUtils.isEmpty(nowParams)) - { + if (StringUtils.isEmpty(nowParams)) { nowParams = JSONObject.toJSONString(request.getParameterMap()); } Map nowDataMap = new HashMap(); @@ -72,8 +68,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor // 唯一值(没有消息头则使用请求地址) String submitKey = request.getHeader(header); - if (StringUtils.isEmpty(submitKey)) - { + if (StringUtils.isEmpty(submitKey)) { submitKey = url; } @@ -81,14 +76,11 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + submitKey; Object sessionObj = redisCache.getCacheObject(cache_repeat_key); - if (sessionObj != null) - { + if (sessionObj != null) { Map sessionMap = (Map) sessionObj; - if (sessionMap.containsKey(url)) - { + if (sessionMap.containsKey(url)) { Map preDataMap = (Map) sessionMap.get(url); - if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) - { + if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) { return true; } } @@ -102,8 +94,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor /** * 判断参数是否相同 */ - private boolean compareParams(Map nowMap, Map preMap) - { + private boolean compareParams(Map nowMap, Map preMap) { String nowParams = (String) nowMap.get(REPEAT_PARAMS); String preParams = (String) preMap.get(REPEAT_PARAMS); return nowParams.equals(preParams); @@ -112,12 +103,10 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor /** * 判断两次间隔时间 */ - private boolean compareTime(Map nowMap, Map preMap) - { + private boolean compareTime(Map nowMap, Map preMap) { long time1 = (Long) nowMap.get(REPEAT_TIME); long time2 = (Long) preMap.get(REPEAT_TIME); - if ((time1 - time2) < (this.intervalTime * 1000)) - { + if ((time1 - time2) < (this.intervalTime * 1000)) { return true; } return false; diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/security/filter/JwtAuthenticationTokenFilter.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/security/filter/JwtAuthenticationTokenFilter.java index 06a9e0c..cdc193f 100644 --- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/security/filter/JwtAuthenticationTokenFilter.java +++ b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/security/filter/JwtAuthenticationTokenFilter.java @@ -17,6 +17,7 @@ import com.hchyun.common.utils.StringUtils; import com.hchyun.framework.web.service.TokenService; /** + * todo token 拦截器 * token过滤器 验证token有效性 * * @author hchyun