mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-30 08:57:09 +08:00
refactor: 重构原有文件上传接口并优化配置文件配置格式
移除 ContiNew Starter 本地存储依赖
This commit is contained in:
@@ -63,6 +63,7 @@ import top.charles7c.continew.starter.core.util.TemplateUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.R;
|
||||
import top.charles7c.continew.starter.log.common.annotation.Log;
|
||||
import top.charles7c.continew.starter.messaging.mail.util.MailUtils;
|
||||
|
||||
/**
|
||||
@@ -84,6 +85,7 @@ public class CaptchaController {
|
||||
private final ProjectProperties projectProperties;
|
||||
private final GraphicCaptchaProperties graphicCaptchaProperties;
|
||||
|
||||
@Log(ignore = true)
|
||||
@Operation(summary = "获取行为验证码", description = "获取行为验证码(Base64编码)")
|
||||
@GetMapping("/behavior")
|
||||
public R<Object> getBehaviorCaptcha(CaptchaVO captchaReq, HttpServletRequest request) {
|
||||
@@ -91,12 +93,14 @@ public class CaptchaController {
|
||||
return R.ok(captchaService.get(captchaReq).getRepData());
|
||||
}
|
||||
|
||||
@Log(ignore = true)
|
||||
@Operation(summary = "校验行为验证码", description = "校验行为验证码")
|
||||
@PostMapping("/behavior")
|
||||
public R<Object> checkBehaviorCaptcha(@RequestBody CaptchaVO captchaReq) {
|
||||
return R.ok(captchaService.check(captchaReq));
|
||||
}
|
||||
|
||||
@Log(ignore = true)
|
||||
@Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)")
|
||||
@GetMapping("/img")
|
||||
public R<CaptchaResp> getImageCaptcha() {
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package top.charles7c.continew.admin.webapi.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -32,8 +31,8 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.dromara.x.file.storage.core.FileInfo;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -52,14 +51,11 @@ import top.charles7c.continew.admin.system.model.query.RoleQuery;
|
||||
import top.charles7c.continew.admin.system.model.resp.RoleResp;
|
||||
import top.charles7c.continew.admin.system.service.*;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
import top.charles7c.continew.starter.core.util.FileUploadUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.base.IBaseEnum;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.R;
|
||||
import top.charles7c.continew.starter.log.common.annotation.Log;
|
||||
import top.charles7c.continew.starter.storage.local.autoconfigure.LocalStorageProperties;
|
||||
|
||||
/**
|
||||
* 公共 API
|
||||
@@ -75,26 +71,20 @@ import top.charles7c.continew.starter.storage.local.autoconfigure.LocalStoragePr
|
||||
@RequestMapping("/common")
|
||||
public class CommonController {
|
||||
|
||||
private final ProjectProperties projectProperties;
|
||||
private final FileService fileService;
|
||||
private final DeptService deptService;
|
||||
private final MenuService menuService;
|
||||
private final RoleService roleService;
|
||||
private final DictItemService dictItemService;
|
||||
private final ProjectProperties projectProperties;
|
||||
private final LocalStorageProperties localStorageProperties;
|
||||
private final OptionService optionService;
|
||||
|
||||
@Operation(summary = "上传文件", description = "上传文件")
|
||||
@PostMapping("/file")
|
||||
public R<String> upload(@NotNull(message = "文件不能为空") MultipartFile file) {
|
||||
ValidationUtils.throwIf(file::isEmpty, "文件不能为空");
|
||||
LocalStorageProperties.LocalStorageMapping storageMapping = localStorageProperties.getMapping().get("FILE");
|
||||
DataSize maxFileSize = storageMapping.getMaxFileSize();
|
||||
CheckUtils.throwIf(file.getSize() > maxFileSize.toBytes(), "请上传小于 {}MB 的文件", maxFileSize.toMegabytes());
|
||||
String filePath = storageMapping.getLocation();
|
||||
File newFile = FileUploadUtils.upload(file, filePath, false);
|
||||
CheckUtils.throwIfNull(newFile, "上传文件失败");
|
||||
assert null != newFile;
|
||||
return R.ok("上传成功", newFile.getName());
|
||||
FileInfo fileInfo = fileService.upload(file);
|
||||
return R.ok("上传成功", fileInfo.getUrl());
|
||||
}
|
||||
|
||||
@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
|
||||
|
Reference in New Issue
Block a user