【fix sonar】CommonController.java文件
This commit is contained in:
+16
-9
@@ -3,14 +3,14 @@ package com.jero.modules.system.controller;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -18,7 +18,6 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
@@ -30,6 +29,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 前端控制器
|
||||
@@ -63,12 +64,14 @@ public class CommonController {
|
||||
@Value(value="${jero.fileSuffixLimits}")
|
||||
private String[] fileSuffixLimits;
|
||||
|
||||
private static String UTF8 ="UTF-8";
|
||||
|
||||
/**
|
||||
* @Author 政辉
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/403")
|
||||
public Result<?> noauth() {
|
||||
public Result<String> noauth() {
|
||||
return Result.error("没有权限,请联系管理员授权");
|
||||
}
|
||||
|
||||
@@ -92,6 +95,8 @@ public class CommonController {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = multipartRequest.getFile("file");
|
||||
if(file==null)
|
||||
return result;
|
||||
// 文件类型是否处于黑名单
|
||||
if(CommonUtils.limitFileSuffix(file.getOriginalFilename(),fileSuffixLimits)){
|
||||
result.setMessage("该文件类型不允许上传");
|
||||
@@ -171,11 +176,13 @@ public class CommonController {
|
||||
fileName = ossFile.getFileName();
|
||||
inputStream = MinioUtil.getMinioFile(MinioUtil.getBucketName(), url);
|
||||
}
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"iso-8859-1"));
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes(UTF8),StandardCharsets.ISO_8859_1));
|
||||
response.setContentType("application/force-download");// 设置强制下载不打开
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
if(inputStream==null)
|
||||
return;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
@@ -252,7 +259,7 @@ public class CommonController {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("X-Access-Token", token);
|
||||
// 发送请求
|
||||
String httpURL = URLDecoder.decode(url, "UTF-8");
|
||||
String httpURL = URLDecoder.decode(url, UTF8);
|
||||
ResponseEntity<String> response = RestUtil.request(httpURL, method, headers , variables, params, String.class);
|
||||
// 封装返回结果
|
||||
Result<Object> result = new Result<>();
|
||||
@@ -286,7 +293,7 @@ public class CommonController {
|
||||
public void view(HttpServletRequest request, HttpServletResponse response) {
|
||||
// ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
String imgPath = extractPathFromPattern(request);
|
||||
if(oConvertUtils.isEmpty(imgPath) || imgPath=="null"){
|
||||
if(oConvertUtils.isEmpty(imgPath) || "null".equals(imgPath)){
|
||||
return;
|
||||
}
|
||||
// 其余处理略
|
||||
@@ -304,7 +311,7 @@ public class CommonController {
|
||||
throw new RuntimeException("文件["+imgPath+"]不存在..");
|
||||
}
|
||||
response.setContentType("application/force-download");// 设置强制下载不打开
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes(UTF8), StandardCharsets.ISO_8859_1));
|
||||
inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
|
||||
Reference in New Issue
Block a user