Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
12fe215d50
@ -66,12 +66,13 @@ public class FileController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{configId}/get/**")
|
@GetMapping("/{configId}/get/{fileDate}/**")
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@Operation(summary = "下载文件")
|
@Operation(summary = "下载文件")
|
||||||
@Parameter(name = "configId", description = "配置编号", required = true)
|
@Parameter(name = "configId", description = "配置编号", required = true)
|
||||||
public void getFileContent(HttpServletRequest request,
|
public void getFileContent(HttpServletRequest request,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
|
@PathVariable("fileDate") String fileDate,
|
||||||
@PathVariable("configId") Long configId) throws Exception {
|
@PathVariable("configId") Long configId) throws Exception {
|
||||||
// 获取请求的路径
|
// 获取请求的路径
|
||||||
String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
|
String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
|
||||||
@ -81,8 +82,14 @@ public class FileController {
|
|||||||
// 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
// 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
||||||
path = URLUtil.decode(path);
|
path = URLUtil.decode(path);
|
||||||
|
|
||||||
|
//去除路径时间信息
|
||||||
|
String[] parts = path.split("/");
|
||||||
|
if (parts.length > 1) { path = parts[1]; }
|
||||||
|
|
||||||
|
//拼接时间路径
|
||||||
|
String filePath = fileDate+"\\"+path;
|
||||||
// 读取内容
|
// 读取内容
|
||||||
byte[] content = fileService.getFileContent(configId, path);
|
byte[] content = fileService.getFileContent(configId, filePath);
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||||
response.setStatus(HttpStatus.NOT_FOUND.value());
|
response.setStatus(HttpStatus.NOT_FOUND.value());
|
||||||
|
@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地文件客户端
|
* 本地文件客户端
|
||||||
@ -26,11 +28,17 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String upload(byte[] content, String path, String type) {
|
public String upload(byte[] content, String path, String type) {
|
||||||
// 执行写入
|
//文件路径加上当前时间
|
||||||
String filePath = getFilePath(path);
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
String date = now.format(formatter); //当前时间
|
||||||
|
String fPath = date+"\\"+path; //文件路径
|
||||||
|
String uPath = date+"/"+path; //url路径
|
||||||
|
// 执行写入文件路径
|
||||||
|
String filePath = getFilePath(fPath);
|
||||||
FileUtil.writeBytes(content, filePath);
|
FileUtil.writeBytes(content, filePath);
|
||||||
// 拼接返回路径
|
// 拼接url路径返回路径
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), uPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user