mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 00:57:13 +08:00 
			
		
		
		
	refactor: 适配 ContiNew Starter Local Storage(存储模块-本地存储)
This commit is contained in:
		| @@ -33,6 +33,7 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
|  | ||||
| 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; | ||||
| @@ -42,7 +43,6 @@ import cn.hutool.core.lang.tree.Tree; | ||||
| import cn.hutool.core.util.ClassUtil; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
|  | ||||
| import top.charles7c.continew.admin.common.config.properties.LocalStorageProperties; | ||||
| import top.charles7c.continew.admin.common.constant.CacheConstants; | ||||
| import top.charles7c.continew.admin.common.model.resp.LabelValueResp; | ||||
| import top.charles7c.continew.admin.system.model.query.DeptQuery; | ||||
| @@ -59,6 +59,7 @@ import top.charles7c.continew.starter.data.mybatis.plus.enums.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 | ||||
| @@ -86,9 +87,10 @@ public class CommonController { | ||||
|     @PostMapping("/file") | ||||
|     public R<String> upload(@NotNull(message = "文件不能为空") MultipartFile file) { | ||||
|         ValidationUtils.throwIf(file::isEmpty, "文件不能为空"); | ||||
|         Long maxSizeInMb = localStorageProperties.getMaxSizeInMb(); | ||||
|         CheckUtils.throwIf(file.getSize() > maxSizeInMb * 1024 * 1024, "请上传小于 {}MB 的文件", maxSizeInMb); | ||||
|         String filePath = localStorageProperties.getPath().getFile(); | ||||
|         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; | ||||
|   | ||||
| @@ -208,27 +208,18 @@ spring.servlet: | ||||
|     max-request-size: 20MB | ||||
|  | ||||
| --- ### 本地存储配置 | ||||
| local-storage: | ||||
|   # 文件模式 | ||||
|   filePattern: /file/** | ||||
|   # 头像模式 | ||||
|   avatarPattern: /avatar/** | ||||
|   # 文件上传大小限制 | ||||
|   maxSizeInMb: 10 | ||||
|   # 头像上传大小限制 | ||||
|   avatarMaxSizeInMb: 5 | ||||
|   ## Windows 系统本地存储配置 | ||||
|   windows: | ||||
|     file: C:\${project.app-name}\data\file\ | ||||
|     avatar: C:\${project.app-name}\data\avatar\ | ||||
|   ## Linux 系统本地存储配置 | ||||
|   linux: | ||||
|     file: ./data/file/ | ||||
|     avatar: ./data/avatar/ | ||||
|   ## Mac 系统本地存储配置 | ||||
|   mac: | ||||
|     file: ~/data/file/ | ||||
|     avatar: ~/data/avatar/ | ||||
| continew-starter.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 | ||||
|  | ||||
| --- ### 跨域配置 | ||||
| cors: | ||||
|   | ||||
| @@ -207,27 +207,18 @@ spring.servlet: | ||||
|     max-request-size: 20MB | ||||
|  | ||||
| --- ### 本地存储配置 | ||||
| local-storage: | ||||
|   # 文件模式 | ||||
|   filePattern: /file/** | ||||
|   # 头像模式 | ||||
|   avatarPattern: /avatar/** | ||||
|   # 文件上传大小限制 | ||||
|   maxSizeInMb: 10 | ||||
|   # 头像上传大小限制 | ||||
|   avatarMaxSizeInMb: 5 | ||||
|   ## Windows 系统本地存储配置 | ||||
|   windows: | ||||
|     file: C:\${project.app-name}\data\file\ | ||||
|     avatar: C:\${project.app-name}\data\avatar\ | ||||
|   ## Linux 系统本地存储配置 | ||||
|   linux: | ||||
|     file: ../data/file/ | ||||
|     avatar: ../data/avatar/ | ||||
|   ## Mac 系统本地存储配置 | ||||
|   mac: | ||||
|     file: ~/data/file/ | ||||
|     avatar: ~/data/avatar/ | ||||
| continew-starter.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 | ||||
|  | ||||
| --- ### 跨域配置 | ||||
| cors: | ||||
|   | ||||
| @@ -26,20 +26,19 @@ project: | ||||
| logging: | ||||
|   config: classpath:logback-spring.xml | ||||
| ## 日志配置 | ||||
| continew-starter: | ||||
|   log: | ||||
|     enabled: true | ||||
|     include: | ||||
|       - DESCRIPTION | ||||
|       - MODULE | ||||
|       - REQUEST_HEADERS | ||||
|       - REQUEST_BODY | ||||
|       - IP_ADDRESS | ||||
|       - BROWSER | ||||
|       - OS | ||||
|       - RESPONSE_HEADERS | ||||
|       - RESPONSE_BODY | ||||
|       - TIME_TAKEN | ||||
| continew-starter.log: | ||||
|   enabled: true | ||||
|   include: | ||||
|     - DESCRIPTION | ||||
|     - MODULE | ||||
|     - REQUEST_HEADERS | ||||
|     - REQUEST_BODY | ||||
|     - IP_ADDRESS | ||||
|     - BROWSER | ||||
|     - OS | ||||
|     - RESPONSE_HEADERS | ||||
|     - RESPONSE_BODY | ||||
|     - TIME_TAKEN | ||||
|  | ||||
| --- ### 接口文档配置 | ||||
| springdoc: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user