mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
【修复】访问数据库存储的文件,path 多层级时,无法访问的问题
This commit is contained in:
parent
3310b766bc
commit
92ace031fe
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.infra.controller.admin.file;
|
package cn.iocoder.yudao.module.infra.controller.admin.file;
|
||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
|
||||||
@ -13,7 +14,6 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
|
|||||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -24,6 +24,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.annotation.security.PermitAll;
|
import javax.annotation.security.PermitAll;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
@ -57,16 +58,20 @@ public class FileController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{configId}/get/{path}")
|
@GetMapping("/{configId}/get/**")
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@ApiOperation("下载文件")
|
@ApiOperation("下载文件")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class)
|
||||||
@ApiImplicitParam(name = "configId", value = "配置编号", required = true, dataTypeClass = Long.class),
|
public void getFileContent(HttpServletRequest request,
|
||||||
@ApiImplicitParam(name = "path", value = "文件路径", required = true, dataTypeClass = String.class)
|
HttpServletResponse response,
|
||||||
})
|
@PathVariable("configId") Long configId) throws Exception {
|
||||||
public void getFileContent(HttpServletResponse response,
|
// 获取请求的路径
|
||||||
@PathVariable("configId") Long configId,
|
String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
|
||||||
@PathVariable("path") String path) throws Exception {
|
if (StrUtil.isEmpty(path)) {
|
||||||
|
throw new IllegalArgumentException("结尾的 path 路径必须传递");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取内容
|
||||||
byte[] content = fileService.getFileContent(configId, path);
|
byte[] content = fileService.getFileContent(configId, path);
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||||
|
@ -27,7 +27,7 @@ public class SecurityConfiguration {
|
|||||||
.antMatchers("/swagger-resources/**").anonymous()
|
.antMatchers("/swagger-resources/**").anonymous()
|
||||||
.antMatchers("/webjars/**").anonymous()
|
.antMatchers("/webjars/**").anonymous()
|
||||||
.antMatchers("/*/api-docs").anonymous();
|
.antMatchers("/*/api-docs").anonymous();
|
||||||
//积木报表
|
// 积木报表
|
||||||
registry.antMatchers("/jmreport/**").permitAll();
|
registry.antMatchers("/jmreport/**").permitAll();
|
||||||
// Spring Boot Actuator 的安全配置
|
// Spring Boot Actuator 的安全配置
|
||||||
registry.antMatchers("/actuator").anonymous()
|
registry.antMatchers("/actuator").anonymous()
|
||||||
@ -37,6 +37,8 @@ public class SecurityConfiguration {
|
|||||||
// Spring Boot Admin Server 的安全配置
|
// Spring Boot Admin Server 的安全配置
|
||||||
registry.antMatchers(adminSeverContextPath).anonymous()
|
registry.antMatchers(adminSeverContextPath).anonymous()
|
||||||
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
||||||
|
// 文件读取
|
||||||
|
registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -68,11 +68,11 @@
|
|||||||
<!-- <version>${revision}</version>-->
|
<!-- <version>${revision}</version>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
<!-- 工作流 -->
|
<!-- 工作流 -->
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>cn.iocoder.boot</groupId>
|
<!-- <groupId>cn.iocoder.boot</groupId>-->
|
||||||
<artifactId>yudao-module-bpm-biz</artifactId>
|
<!-- <artifactId>yudao-module-bpm-biz</artifactId>-->
|
||||||
<version>${revision}</version>
|
<!-- <version>${revision}</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.iocoder.boot</groupId>
|
<groupId>cn.iocoder.boot</groupId>
|
||||||
<artifactId>yudao-spring-boot-starter-biz-error-code</artifactId>
|
<artifactId>yudao-spring-boot-starter-biz-error-code</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user