refactor(system): 重构存储配置及文件上传相关代码

存储配置自动处理:domain 不能以 / 结尾,bucket 必须以 / 结尾
文件上传:path 自动处理

Closes #IC6V43
This commit is contained in:
2025-05-14 23:01:08 +08:00
parent cd4adcf7a2
commit bc057da265
9 changed files with 261 additions and 219 deletions

View File

@@ -35,8 +35,6 @@ import top.continew.admin.system.enums.OptionCategoryEnum;
import top.continew.admin.system.model.query.*;
import top.continew.admin.system.model.resp.file.FileUploadResp;
import top.continew.admin.system.service.*;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.StrUtils;
import top.continew.starter.core.validation.ValidationUtils;
import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.LabelValueResp;
@@ -71,9 +69,7 @@ public class CommonController {
@PostMapping("/file")
public FileUploadResp upload(@NotNull(message = "文件不能为空") MultipartFile file, String path) throws IOException {
ValidationUtils.throwIf(file::isEmpty, "文件不能为空");
String fixedPath = StrUtils.blankToDefault(path, StringConstants.SLASH, p -> StrUtil
.appendIfMissing(p, StringConstants.SLASH));
FileInfo fileInfo = fileService.upload(file, fixedPath);
FileInfo fileInfo = fileService.upload(file, path);
return FileUploadResp.builder()
.id(fileInfo.getId())
.url(fileInfo.getUrl())