ftp文件下载完成

This commit is contained in:
20932067@zju.edu.cn 2021-02-19 15:10:44 +08:00
parent d81a683b51
commit ba0cb8273a
6 changed files with 30 additions and 42 deletions

View File

@ -1,14 +1,12 @@
import axios from "axios"; import axios from "axios";
import {getToken} from "@/utils/auth"; import {getToken} from "@/utils/auth";
export function downloadFile(fileId){ export function downloadFile(fileId) {
axios({ return axios({
method:'get', method: 'get',
url:process.env.VUE_APP_BASE_API+'/system/file/download/'+fileId, url: process.env.VUE_APP_BASE_API + '/system/file/download/' + fileId,
headers:{ headers: {
token:'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 token: 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
} }
}).then(res=>{
return res;
}) })
} }

View File

@ -344,8 +344,7 @@ export default {
}).then(function (){ }).then(function (){
return downloadFile(row.fileId) return downloadFile(row.fileId)
}).then(res =>{ }).then(res =>{
console.log(res) this.download(res.data.msg);
// this.download(data.msg);
}) })
}, },
// //

View File

@ -39,9 +39,9 @@ public class CommonController {
@GetMapping("common/download") @GetMapping("common/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) { public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
try { try {
if (!FileUtils.isValidFilename(fileName)) { // if (!FileUtils.isValidFilename(fileName)) {
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 " , fileName)); // throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 " , fileName));
} // }
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1); String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = HchYunConfig.getDownloadPath() + fileName; String filePath = HchYunConfig.getDownloadPath() + fileName;

View File

@ -68,6 +68,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
File file = new File(filePath); File file = new File(filePath);
// 路径为文件且不为空则进行删除 // 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) { if (file.isFile() && file.exists()) {
System.gc();
file.delete(); file.delete();
flag = true; flag = true;
} }

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -22,8 +23,7 @@ import com.hchyun.framework.interceptor.RepeatSubmitInterceptor;
* @author hchyun * @author hchyun
*/ */
@Component @Component
public class SameUrlDataInterceptor extends RepeatSubmitInterceptor public class SameUrlDataInterceptor extends RepeatSubmitInterceptor {
{
public final String REPEAT_PARAMS = "repeatParams"; public final String REPEAT_PARAMS = "repeatParams";
public final String REPEAT_TIME = "repeatTime"; public final String REPEAT_TIME = "repeatTime";
@ -37,30 +37,26 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
/** /**
* 间隔时间单位: 默认10秒 * 间隔时间单位: 默认10秒
* * <p>
* 两次相同参数的请求如果间隔时间大于该参数系统不会认定为重复提交的数据 * 两次相同参数的请求如果间隔时间大于该参数系统不会认定为重复提交的数据
*/ */
private int intervalTime = 10; private int intervalTime = 10;
public void setIntervalTime(int intervalTime) public void setIntervalTime(int intervalTime) {
{
this.intervalTime = intervalTime; this.intervalTime = intervalTime;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public boolean isRepeatSubmit(HttpServletRequest request) public boolean isRepeatSubmit(HttpServletRequest request) {
{
String nowParams = ""; String nowParams = "";
if (request instanceof RepeatedlyRequestWrapper) if (request instanceof RepeatedlyRequestWrapper) {
{
RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request;
nowParams = HttpHelper.getBodyString(repeatedlyRequest); nowParams = HttpHelper.getBodyString(repeatedlyRequest);
} }
// body参数为空获取Parameter的数据 // body参数为空获取Parameter的数据
if (StringUtils.isEmpty(nowParams)) if (StringUtils.isEmpty(nowParams)) {
{
nowParams = JSONObject.toJSONString(request.getParameterMap()); nowParams = JSONObject.toJSONString(request.getParameterMap());
} }
Map<String, Object> nowDataMap = new HashMap<String, Object>(); Map<String, Object> nowDataMap = new HashMap<String, Object>();
@ -72,8 +68,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
// 唯一值没有消息头则使用请求地址 // 唯一值没有消息头则使用请求地址
String submitKey = request.getHeader(header); String submitKey = request.getHeader(header);
if (StringUtils.isEmpty(submitKey)) if (StringUtils.isEmpty(submitKey)) {
{
submitKey = url; submitKey = url;
} }
@ -81,14 +76,11 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + submitKey; String cache_repeat_key = Constants.REPEAT_SUBMIT_KEY + submitKey;
Object sessionObj = redisCache.getCacheObject(cache_repeat_key); Object sessionObj = redisCache.getCacheObject(cache_repeat_key);
if (sessionObj != null) if (sessionObj != null) {
{
Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; Map<String, Object> sessionMap = (Map<String, Object>) sessionObj;
if (sessionMap.containsKey(url)) if (sessionMap.containsKey(url)) {
{
Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url); Map<String, Object> preDataMap = (Map<String, Object>) sessionMap.get(url);
if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) if (compareParams(nowDataMap, preDataMap) && compareTime(nowDataMap, preDataMap)) {
{
return true; return true;
} }
} }
@ -102,8 +94,7 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
/** /**
* 判断参数是否相同 * 判断参数是否相同
*/ */
private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) private boolean compareParams(Map<String, Object> nowMap, Map<String, Object> preMap) {
{
String nowParams = (String) nowMap.get(REPEAT_PARAMS); String nowParams = (String) nowMap.get(REPEAT_PARAMS);
String preParams = (String) preMap.get(REPEAT_PARAMS); String preParams = (String) preMap.get(REPEAT_PARAMS);
return nowParams.equals(preParams); return nowParams.equals(preParams);
@ -112,12 +103,10 @@ public class SameUrlDataInterceptor extends RepeatSubmitInterceptor
/** /**
* 判断两次间隔时间 * 判断两次间隔时间
*/ */
private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap) private boolean compareTime(Map<String, Object> nowMap, Map<String, Object> preMap) {
{
long time1 = (Long) nowMap.get(REPEAT_TIME); long time1 = (Long) nowMap.get(REPEAT_TIME);
long time2 = (Long) preMap.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 true;
} }
return false; return false;

View File

@ -17,6 +17,7 @@ import com.hchyun.common.utils.StringUtils;
import com.hchyun.framework.web.service.TokenService; import com.hchyun.framework.web.service.TokenService;
/** /**
* todo token 拦截器
* token过滤器 验证token有效性 * token过滤器 验证token有效性
* *
* @author hchyun * @author hchyun