Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
12fe215d50
@ -66,12 +66,13 @@ public class FileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/{configId}/get/**")
|
||||
@GetMapping("/{configId}/get/{fileDate}/**")
|
||||
@PermitAll
|
||||
@Operation(summary = "下载文件")
|
||||
@Parameter(name = "configId", description = "配置编号", required = true)
|
||||
public void getFileContent(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable("fileDate") String fileDate,
|
||||
@PathVariable("configId") Long configId) throws Exception {
|
||||
// 获取请求的路径
|
||||
String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
|
||||
@ -81,8 +82,14 @@ public class FileController {
|
||||
// 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
||||
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) {
|
||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||
response.setStatus(HttpStatus.NOT_FOUND.value());
|
||||
|
@ -74,4 +74,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||
return config.getBasePath() + path;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
@ -26,11 +28,17 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||
|
||||
@Override
|
||||
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);
|
||||
// 拼接返回路径
|
||||
return super.formatFileUrl(config.getDomain(), path);
|
||||
// 拼接url路径返回路径
|
||||
return super.formatFileUrl(config.getDomain(), uPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user