取消minio 全局跨域请求

This commit is contained in:
fuce1314 2022-11-01 21:16:44 +08:00
parent 12ba938bc8
commit d16d2c0d76
7 changed files with 109 additions and 18 deletions

View File

@ -37,6 +37,10 @@ public class V2Config
/** shiro不拦截url配置 **/ /** shiro不拦截url配置 **/
private List<String> saTokenNotFilterUrl; private List<String> saTokenNotFilterUrl;
private String defaultBaseDir;
/**图片请求地址**/
private String uploadImgUrl;
public String getName() { public String getName() {
return name; return name;
} }
@ -103,5 +107,17 @@ public class V2Config
public void setSaTokenNotFilterUrl(List<String> saTokenNotFilterUrl) { public void setSaTokenNotFilterUrl(List<String> saTokenNotFilterUrl) {
this.saTokenNotFilterUrl = saTokenNotFilterUrl; this.saTokenNotFilterUrl = saTokenNotFilterUrl;
} }
public String getDefaultBaseDir() {
return defaultBaseDir;
}
public void setDefaultBaseDir(String defaultBaseDir) {
this.defaultBaseDir = defaultBaseDir;
}
public String getUploadImgUrl() {
return uploadImgUrl;
}
public void setUploadImgUrl(String uploadImgUrl) {
this.uploadImgUrl = uploadImgUrl;
}
} }

View File

@ -60,7 +60,7 @@ public class GlobalExceptionResolver{
return JSON.toJSONString(AjaxResult.error(886,e.getMessage())); return JSON.toJSONString(AjaxResult.error(886,e.getMessage()));
} }
} }
return new ModelAndView("/login"); return new ModelAndView("login");
} }
// 权限认证异常 // 权限认证异常
else if (e instanceof NotPermissionException || e instanceof NotRoleException || e instanceof NotSafeException){ else if (e instanceof NotPermissionException || e instanceof NotRoleException || e instanceof NotSafeException){

View File

@ -1,10 +1,15 @@
package com.fc.v2.common.interceptor; package com.fc.v2.common.interceptor;
import java.io.File;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.fc.v2.common.conf.V2Config;
/** /**
* 拦截器 * 拦截器
* @ClassName: MyWebAppConfigurer * @ClassName: MyWebAppConfigurer
@ -14,6 +19,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
*/ */
@Configuration @Configuration
public class MyWebAppConfigurer implements WebMvcConfigurer { public class MyWebAppConfigurer implements WebMvcConfigurer {
@Autowired
private V2Config v2Config;
/** 添加拦截器 **/ /** 添加拦截器 **/
@Override @Override
@ -25,7 +32,8 @@ public class MyWebAppConfigurer implements WebMvcConfigurer {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
//配置虚拟路径为项目得static下面 //配置虚拟路径为项目得static下面
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("/static/**").addResourceLocations("classpath:"+File.separator+"static"+File.separator);
registry.addResourceHandler("/static/file_upload/**").addResourceLocations("file:"+v2Config.getDefaultBaseDir()+File.separator);
//添加swagger //添加swagger
// registry.addResourceHandler("swagger-ui.html").addResourceLocations( // registry.addResourceHandler("swagger-ui.html").addResourceLocations(
// "classpath:/META-INF/resources/"); // "classpath:/META-INF/resources/");

View File

@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.fc.v2.common.conf.V2Config;
import com.fc.v2.common.conf.oss.OssTemplate; import com.fc.v2.common.conf.oss.OssTemplate;
import com.fc.v2.common.domain.AjaxResult; import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.mapper.custom.TsysUserDao; import com.fc.v2.mapper.custom.TsysUserDao;
@ -41,6 +43,8 @@ public class GoViewController {
//系统用户 //系统用户
@Autowired @Autowired
public SysUserService sysUserService; public SysUserService sysUserService;
@Autowired
private V2Config v2Config;
/** /**
* 手机登录 * 手机登录
@ -158,17 +162,7 @@ public class GoViewController {
@ResponseBody @ResponseBody
public AjaxResult OssInfo(HttpServletRequest request) { public AjaxResult OssInfo(HttpServletRequest request) {
Map<String, String> ossinfo=new HashMap<String, String>(); Map<String, String> ossinfo=new HashMap<String, String>();
StringBuffer buffer=new StringBuffer("http://"+request.getServerName()); ossinfo.put("bucketURL",v2Config.getUploadImgUrl());
if(80!=request.getServerPort()) {
buffer.append(":"+request.getServerPort());
}
if(StrUtil.isNotEmpty(request.getContextPath())) {
buffer.append(""+request.getContextPath());
}
buffer.append("/oss/object/"+template.getOssProperties().getBucketName());
ossinfo.put("bucketURL",buffer.toString());
ossinfo.put("BucketName",template.getOssProperties().getBucketName());
return AjaxResult.successData(200, ossinfo).put("msg", "返回成功"); return AjaxResult.successData(200, ossinfo).put("msg", "返回成功");
} }

View File

@ -1,27 +1,38 @@
package com.fc.v2.controller.admin.goview; package com.fc.v2.controller.admin.goview;
import com.amazonaws.services.s3.model.PutObjectResult;
import com.fc.v2.common.base.BaseController; import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.conf.V2Config;
import com.fc.v2.common.domain.AjaxResult; import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable; import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.auto.GoviewProject; import com.fc.v2.model.auto.GoviewProject;
import com.fc.v2.model.auto.GoviewProjectData; import com.fc.v2.model.auto.GoviewProjectData;
import com.fc.v2.model.auto.GoviewProjectDataExample; import com.fc.v2.model.auto.GoviewProjectDataExample;
import com.fc.v2.model.auto.SysFile;
import com.fc.v2.model.custom.GoviewProjectVo; import com.fc.v2.model.custom.GoviewProjectVo;
import com.fc.v2.model.custom.MagicHttp; import com.fc.v2.model.custom.MagicHttp;
import com.fc.v2.model.custom.Tablepar; import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.satoken.SaTokenUtil;
import com.fc.v2.service.GoviewProjectDataService; import com.fc.v2.service.GoviewProjectDataService;
import com.fc.v2.service.GoviewProjectService; import com.fc.v2.service.GoviewProjectService;
import com.fc.v2.service.SysFileService;
import com.fc.v2.util.BeanUtils; import com.fc.v2.util.BeanUtils;
import com.fc.v2.util.SnowflakeIdWorker;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -30,6 +41,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/** /**
* 项目表Controller * 项目表Controller
@ -47,8 +59,10 @@ public class GoviewProjectAPi extends BaseController{
private GoviewProjectService goviewProjectService; private GoviewProjectService goviewProjectService;
@Autowired @Autowired
private GoviewProjectDataService goviewProjectDataService; private GoviewProjectDataService goviewProjectDataService;
@Autowired
private SysFileService sysFileService;
@Autowired
private V2Config v2Config;
/** /**
* list集合 * list集合
@ -276,4 +290,58 @@ public class GoviewProjectAPi extends BaseController{
/**
* 上传文件
* @param object 文件流对象
* @param bucketName 桶名
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
public AjaxResult upload(@RequestBody MultipartFile object) throws IOException{
String fileName = object.getOriginalFilename();
String suffixName=".png";
String mediaKey="";
//文件名字
String fileSuffixName="";
if(fileName.lastIndexOf(".")!=-1) {//有后缀
suffixName = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
mediaKey=MD5.create().digestHex(fileName);
fileSuffixName=mediaKey+suffixName;
}else {//无后缀
//取得唯一id
mediaKey = MD5.create().digestHex(fileName+suffixName);
fileSuffixName=mediaKey+suffixName;
}
SysFile sysFile=sysFileService.selectByExamplefileName(fileSuffixName);
File desc = getAbsoluteFile(v2Config.getDefaultBaseDir(),fileSuffixName);
object.transferTo(desc);
if(sysFile!=null){//修改
}else{
sysFile=new SysFile(SnowflakeIdWorker.getUUID(), fileSuffixName, null, object.getSize(), object.getContentType(),"-", "-", new Date(),null, null, null);
sysFileService.insertSelective(sysFile);
}
return AjaxResult.successData(200, sysFile);
}
private final File getAbsoluteFile(String uploadDir, String filename) throws IOException
{
File desc = new File(uploadDir+File.separator + filename);
if (!desc.getParentFile().exists())
{
desc.getParentFile().mkdirs();
}
if (!desc.exists())
{
desc.createNewFile();
}
return desc;
}
} }

View File

@ -91,7 +91,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return JSON.toJSONString(AjaxResult.error(886,e.getMessage())); return JSON.toJSONString(AjaxResult.error(886,e.getMessage()));
} }
} }
SaHolder.getResponse().redirect("/admin/login"); SaHolder.getRequest().forward("/admin/login");
} }
return JSON.toJSONString(AjaxResult.error(e.getMessage())); return JSON.toJSONString(AjaxResult.error(e.getMessage()));
}) })

View File

@ -23,12 +23,17 @@ fuce:
xss-not-filter-url: [/api/v1/token/api_token,/api/goview/project/save/data] xss-not-filter-url: [/api/v1/token/api_token,/api/goview/project/save/data]
#satoken不拦截url #satoken不拦截url
sa-token-not-filter-url: [/api/goview/sys/*,/api/goview/project/**] sa-token-not-filter-url: [/api/goview/sys/*,/api/goview/project/**]
is-root-upload: true
#文件上传的存放的地址
default-base-dir: D:/v2file
#前端请求文件上传的url配置
upload_img_url: http://localhost:8080/goview//static/file_upload/
#tomcat config #tomcat config
server : server :
port : 8080 port : 8080
##项目名字配置 ##项目名字配置
servlet : servlet :
context-path : /goview context-path : /
tomcat : tomcat :
uri-encoding : UTF-8 uri-encoding : UTF-8
#xx 报错修改的地方 #xx 报错修改的地方