mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-26 20:57:11 +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 = "查询树结构的部门列表")
|
||||
|
||||
@@ -84,6 +84,22 @@ spring.cache:
|
||||
cache-null-values: true
|
||||
|
||||
--- ### 验证码配置
|
||||
continew-starter.captcha:
|
||||
## 行为验证码
|
||||
behavior:
|
||||
enabled: true
|
||||
cache-type: REDIS
|
||||
water-mark: ${project.app-name}
|
||||
## 图形验证码
|
||||
graphic:
|
||||
enabled: true
|
||||
# 类型
|
||||
type: SPEC
|
||||
# 内容长度
|
||||
length: 4
|
||||
# 过期时间
|
||||
expirationInMinutes: 2
|
||||
## 其他验证码配置
|
||||
captcha:
|
||||
## 邮箱验证码配置
|
||||
mail:
|
||||
@@ -104,41 +120,33 @@ captcha:
|
||||
# 模板 ID
|
||||
templateId: 1
|
||||
|
||||
--- ### ContiNew Starter 组件配置
|
||||
continew-starter:
|
||||
## 验证码配置
|
||||
captcha:
|
||||
# 行为验证码配置
|
||||
behavior:
|
||||
enabled: true
|
||||
cache-type: REDIS
|
||||
water-mark: ${project.app-name}
|
||||
# 图形验证码配置
|
||||
graphic:
|
||||
enabled: true
|
||||
# 类型
|
||||
type: SPEC
|
||||
# 内容长度
|
||||
length: 4
|
||||
# 过期时间
|
||||
expirationInMinutes: 2
|
||||
## 日志配置
|
||||
log:
|
||||
# 是否打印日志,开启后可打印访问日志(类似于 Nginx access log)
|
||||
is-print: true
|
||||
## 本地存储配置
|
||||
storage:
|
||||
local:
|
||||
enabled: true
|
||||
mapping:
|
||||
FILE:
|
||||
path-pattern: /file/**
|
||||
location: C:\${project.app-name}\data\file\
|
||||
max-file-size: 10MB
|
||||
AVATAR:
|
||||
path-pattern: /avatar/**
|
||||
location: C:\${project.app-name}\data\avatar\
|
||||
max-file-size: 5MB
|
||||
--- ### 日志配置
|
||||
continew-starter.log:
|
||||
# 是否打印日志,开启后可打印访问日志(类似于 Nginx access log)
|
||||
is-print: true
|
||||
## 项目日志配置(配置重叠部分,优先级高于 logback-spring.xml 中的配置)
|
||||
logging:
|
||||
level:
|
||||
top.charles7c: DEBUG
|
||||
file:
|
||||
path: ./logs
|
||||
|
||||
--- ### 跨域配置
|
||||
continew-starter.cors:
|
||||
enabled: true
|
||||
# 配置允许跨域的域名
|
||||
allowed-origins: '*'
|
||||
# 配置允许跨域的请求方式
|
||||
allowed-methods: '*'
|
||||
# 配置允许跨域的请求头
|
||||
allowed-headers: '*'
|
||||
# 配置允许跨域的响应头
|
||||
exposed-headers: '*'
|
||||
|
||||
--- ### 接口文档配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
|
||||
--- ### 短信配置
|
||||
sms:
|
||||
@@ -169,23 +177,6 @@ spring.mail:
|
||||
class: javax.net.ssl.SSLSocketFactory
|
||||
port: 465
|
||||
|
||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||
rsa:
|
||||
# 私钥
|
||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||
|
||||
--- ### 日志配置
|
||||
logging:
|
||||
level:
|
||||
top.charles7c: DEBUG
|
||||
file:
|
||||
path: ./logs
|
||||
|
||||
--- ### 接口文档配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: true
|
||||
|
||||
--- ### Just Auth 配置
|
||||
justauth:
|
||||
enabled: true
|
||||
@@ -220,7 +211,6 @@ sa-token.extension:
|
||||
- /swagger-resources/**
|
||||
- /*/api-docs/**
|
||||
# 本地存储资源
|
||||
- /avatar/**
|
||||
- /file/**
|
||||
|
||||
--- ### 文件上传配置
|
||||
@@ -232,14 +222,7 @@ spring.servlet:
|
||||
# 单次总上传文件大小限制
|
||||
max-request-size: 20MB
|
||||
|
||||
--- ### 跨域配置
|
||||
cors:
|
||||
enabled: true
|
||||
# 配置允许跨域的域名
|
||||
allowed-origins: '*'
|
||||
# 配置允许跨域的请求方式
|
||||
allowed-methods: '*'
|
||||
# 配置允许跨域的请求头
|
||||
allowed-headers: '*'
|
||||
# 配置允许跨域的响应头
|
||||
exposed-headers: '*'
|
||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||
rsa:
|
||||
# 私钥
|
||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||
|
||||
@@ -86,6 +86,22 @@ spring.cache:
|
||||
cache-null-values: true
|
||||
|
||||
--- ### 验证码配置
|
||||
continew-starter.captcha:
|
||||
# 行为验证码
|
||||
behavior:
|
||||
enabled: true
|
||||
cache-type: REDIS
|
||||
water-mark: ${project.app-name}
|
||||
# 图形验证码
|
||||
graphic:
|
||||
enabled: true
|
||||
# 类型
|
||||
type: SPEC
|
||||
# 内容长度
|
||||
length: 4
|
||||
# 过期时间
|
||||
expirationInMinutes: 2
|
||||
## 其他验证码配置
|
||||
captcha:
|
||||
## 邮箱验证码配置
|
||||
mail:
|
||||
@@ -106,41 +122,38 @@ captcha:
|
||||
# 模板 ID
|
||||
templateId: 1
|
||||
|
||||
--- ### ContiNew Starter 组件配置
|
||||
continew-starter:
|
||||
## 验证码配置
|
||||
captcha:
|
||||
# 行为验证码配置
|
||||
behavior:
|
||||
enabled: true
|
||||
cache-type: REDIS
|
||||
water-mark: ${project.app-name}
|
||||
# 图形验证码配置
|
||||
graphic:
|
||||
enabled: true
|
||||
# 类型
|
||||
type: SPEC
|
||||
# 内容长度
|
||||
length: 4
|
||||
# 过期时间
|
||||
expirationInMinutes: 2
|
||||
## 日志配置
|
||||
log:
|
||||
# 是否打印日志,开启后可打印访问日志(类似于 Nginx access log)
|
||||
is-print: false
|
||||
## 本地存储配置
|
||||
storage:
|
||||
local:
|
||||
enabled: true
|
||||
mapping:
|
||||
FILE:
|
||||
path-pattern: /file/**
|
||||
location: ../data/file/
|
||||
max-file-size: 10MB
|
||||
AVATAR:
|
||||
path-pattern: /avatar/**
|
||||
location: ../data/avatar/
|
||||
max-file-size: 5MB
|
||||
--- ### 日志配置
|
||||
continew-starter.log:
|
||||
# 是否打印日志,开启后可打印访问日志(类似于 Nginx access log)
|
||||
is-print: false
|
||||
## 项目日志配置(配置重叠部分,优先级高于 logback-spring.xml 中的配置)
|
||||
logging:
|
||||
level:
|
||||
top.charles7c: INFO
|
||||
file:
|
||||
path: ../logs
|
||||
|
||||
--- ### 跨域配置
|
||||
continew-starter.cors:
|
||||
enabled: true
|
||||
# 配置允许跨域的域名
|
||||
allowed-origins:
|
||||
- ${project.url}
|
||||
# 配置允许跨域的请求方式
|
||||
allowed-methods: '*'
|
||||
# 配置允许跨域的请求头
|
||||
allowed-headers: '*'
|
||||
# 配置允许跨域的响应头
|
||||
exposed-headers: '*'
|
||||
|
||||
--- ### 接口文档配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: false
|
||||
## 接口文档增强配置
|
||||
knife4j:
|
||||
# 开启生产环境屏蔽
|
||||
production: true
|
||||
|
||||
--- ### 短信配置
|
||||
sms:
|
||||
@@ -171,27 +184,6 @@ spring.mail:
|
||||
class: javax.net.ssl.SSLSocketFactory
|
||||
port: 465
|
||||
|
||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||
rsa:
|
||||
# 私钥
|
||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||
|
||||
--- ### 日志配置
|
||||
logging:
|
||||
level:
|
||||
top.charles7c: INFO
|
||||
file:
|
||||
path: ../logs
|
||||
|
||||
--- ### 接口文档配置
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
enabled: false
|
||||
## 接口文档增强配置
|
||||
knife4j:
|
||||
# 开启生产环境屏蔽
|
||||
production: true
|
||||
|
||||
--- ### Just Auth 配置
|
||||
justauth:
|
||||
enabled: true
|
||||
@@ -219,7 +211,6 @@ sa-token.extension:
|
||||
- /**/*.js
|
||||
- /webSocket/**
|
||||
# 本地存储资源
|
||||
- /avatar/**
|
||||
- /file/**
|
||||
|
||||
--- ### 文件上传配置
|
||||
@@ -231,15 +222,7 @@ spring.servlet:
|
||||
# 单次总上传文件大小限制
|
||||
max-request-size: 20MB
|
||||
|
||||
--- ### 跨域配置
|
||||
cors:
|
||||
enabled: true
|
||||
# 配置允许跨域的域名
|
||||
allowed-origins:
|
||||
- ${project.url}
|
||||
# 配置允许跨域的请求方式
|
||||
allowed-methods: '*'
|
||||
# 配置允许跨域的请求头
|
||||
allowed-headers: '*'
|
||||
# 配置允许跨域的响应头
|
||||
exposed-headers: '*'
|
||||
--- ### 非对称加密配置(例如:密码加密传输,前端公钥加密,后端私钥解密;在线生成 RSA 密钥对:http://web.chacuo.net/netrsakeypair)
|
||||
rsa:
|
||||
# 私钥
|
||||
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
|
||||
|
||||
@@ -22,10 +22,7 @@ project:
|
||||
# 是否启用本地解析 IP 归属地
|
||||
ip-addr-local-parse-enabled: true
|
||||
|
||||
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
## 日志配置
|
||||
--- ### 日志配置
|
||||
continew-starter.log:
|
||||
enabled: true
|
||||
# 包含信息
|
||||
@@ -39,6 +36,17 @@ continew-starter.log:
|
||||
- OS
|
||||
- RESPONSE_HEADERS
|
||||
- RESPONSE_BODY
|
||||
## 项目日志配置
|
||||
logging:
|
||||
config: classpath:logback-spring.xml
|
||||
|
||||
--- ### 线程池配置
|
||||
continew-starter.thread-pool:
|
||||
enabled: true
|
||||
# 队列容量
|
||||
queue-capacity: 128
|
||||
# 活跃时间(单位:秒)
|
||||
keep-alive-seconds: 300
|
||||
|
||||
--- ### 接口文档配置
|
||||
springdoc:
|
||||
@@ -195,14 +203,6 @@ management.health:
|
||||
# 关闭邮箱健康检查(邮箱配置错误或邮箱服务器不可用时,健康检查会报错)
|
||||
enabled: false
|
||||
|
||||
--- ### 线程池配置
|
||||
thread-pool:
|
||||
enabled: true
|
||||
# 队列容量
|
||||
queue-capacity: 128
|
||||
# 活跃时间(单位:秒)
|
||||
keep-alive-seconds: 300
|
||||
|
||||
--- ### 代码生成器配置
|
||||
generator:
|
||||
# 排除数据表
|
||||
|
||||
@@ -20,5 +20,5 @@ VALUES
|
||||
INSERT IGNORE INTO `sys_storage`
|
||||
(`id`, `name`, `code`, `type`, `access_key`, `secret_key`, `endpoint`, `bucket_name`, `domain`, `description`, `is_default`, `sort`, `status`, `create_user`, `create_time`, `update_user`, `update_time`)
|
||||
VALUES
|
||||
(1, '本地存储-开发环境', 'local-dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file', 'http://localhost:8000/file', '本地存储-开发环境', b'0', 1, 2, 1, NOW(), NULL, NULL),
|
||||
(2, '本地存储', 'local', 2, NULL, NULL, NULL, '../data/file/', 'http://api.charles7c.top/file', '本地存储', b'1', 1, 1, 1, NOW(), NULL, NULL);
|
||||
(1, '本地存储-开发环境', 'local-dev', 2, NULL, NULL, NULL, 'C:/continew-admin/data/file/', 'http://localhost:8000/file', '本地存储-开发环境', b'1', 1, 1, 1, NOW(), NULL, NULL),
|
||||
(2, '本地存储-生产环境', 'local-prod', 2, NULL, NULL, NULL, '../data/file/', 'http://api.charles7c.top/file', '本地存储-生产环境', b'0', 2, 2, 1, NOW(), NULL, NULL);
|
||||
Reference in New Issue
Block a user