Commit 813069abf4400631ea84d3cd545c933304d2aa6f
1 parent
34a7399a
优化文件配置,去掉 region 的配置,通过自动识别
Showing
21 changed files
with
28 additions
and
43 deletions
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java
| ... | ... | @@ -41,12 +41,6 @@ public class S3FileClientConfig implements FileClientConfig { |
| 41 | 41 | @URL(message = "domain 必须是 URL 格式") |
| 42 | 42 | private String domain; |
| 43 | 43 | /** |
| 44 | - * 区域 | |
| 45 | - */ | |
| 46 | -// @NotNull(message = "region 不能为空") | |
| 47 | - @Deprecated | |
| 48 | - private String region; | |
| 49 | - /** | |
| 50 | 44 | * 存储 Bucket |
| 51 | 45 | */ |
| 52 | 46 | @NotNull(message = "bucket 不能为空") | ... | ... |
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
| ... | ... | @@ -15,7 +15,7 @@ public interface FileApi { |
| 15 | 15 | * @param content 文件内容 |
| 16 | 16 | * @return 文件路径 |
| 17 | 17 | */ |
| 18 | - default String createFile(byte[] content) { | |
| 18 | + default String createFile(byte[] content) throws Exception { | |
| 19 | 19 | return createFile(IdUtil.fastUUID(), content); |
| 20 | 20 | } |
| 21 | 21 | |
| ... | ... | @@ -26,6 +26,6 @@ public interface FileApi { |
| 26 | 26 | * @param content 文件内容 |
| 27 | 27 | * @return 文件路径 |
| 28 | 28 | */ |
| 29 | - String createFile(String path, byte[] content); | |
| 29 | + String createFile(String path, byte[] content) throws Exception; | |
| 30 | 30 | |
| 31 | 31 | } | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.api.file; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.infra.api.file.FileApi; | |
| 4 | 3 | import cn.iocoder.yudao.module.infra.service.file.FileService; |
| 5 | 4 | import org.springframework.stereotype.Service; |
| 6 | 5 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -20,7 +19,7 @@ public class FileApiImpl implements FileApi { |
| 20 | 19 | private FileService fileService; |
| 21 | 20 | |
| 22 | 21 | @Override |
| 23 | - public String createFile(String path, byte[] content) { | |
| 22 | + public String createFile(String path, byte[] content) throws Exception { | |
| 24 | 23 | return fileService.createFile(path, content); |
| 25 | 24 | } |
| 26 | 25 | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java
| ... | ... | @@ -82,7 +82,7 @@ public class FileConfigController { |
| 82 | 82 | @GetMapping("/test") |
| 83 | 83 | @ApiOperation("测试文件配置是否正确") |
| 84 | 84 | @PreAuthorize("@ss.hasPermission('infra:file-config:query')") |
| 85 | - public CommonResult<String> testFileConfig(@RequestParam("id") Long id) { | |
| 85 | + public CommonResult<String> testFileConfig(@RequestParam("id") Long id) throws Exception { | |
| 86 | 86 | String url = fileConfigService.testFileConfig(id); |
| 87 | 87 | return success(url); |
| 88 | 88 | } | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
| ... | ... | @@ -23,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile; |
| 23 | 23 | import javax.annotation.Resource; |
| 24 | 24 | import javax.servlet.http.HttpServletResponse; |
| 25 | 25 | import javax.validation.Valid; |
| 26 | -import java.io.IOException; | |
| 27 | 26 | |
| 28 | 27 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | 28 | |
| ... | ... | @@ -44,7 +43,7 @@ public class FileController { |
| 44 | 43 | @ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class) |
| 45 | 44 | }) |
| 46 | 45 | public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file, |
| 47 | - @RequestParam("path") String path) throws IOException { | |
| 46 | + @RequestParam("path") String path) throws Exception { | |
| 48 | 47 | return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream()))); |
| 49 | 48 | } |
| 50 | 49 | |
| ... | ... | @@ -52,7 +51,7 @@ public class FileController { |
| 52 | 51 | @ApiOperation("删除文件") |
| 53 | 52 | @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) |
| 54 | 53 | @PreAuthorize("@ss.hasPermission('infra:file:delete')") |
| 55 | - public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) { | |
| 54 | + public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) throws Exception { | |
| 56 | 55 | fileService.deleteFile(id); |
| 57 | 56 | return success(true); |
| 58 | 57 | } |
| ... | ... | @@ -65,7 +64,7 @@ public class FileController { |
| 65 | 64 | }) |
| 66 | 65 | public void getFileContent(HttpServletResponse response, |
| 67 | 66 | @PathVariable("configId") Long configId, |
| 68 | - @PathVariable("path") String path) throws IOException { | |
| 67 | + @PathVariable("path") String path) throws Exception { | |
| 69 | 68 | byte[] content = fileService.getFileContent(configId, path); |
| 70 | 69 | if (content == null) { |
| 71 | 70 | log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path); | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
| ... | ... | @@ -225,7 +225,7 @@ public class FileConfigServiceImpl implements FileConfigService { |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | @Override |
| 228 | - public String testFileConfig(Long id) { | |
| 228 | + public String testFileConfig(Long id) throws Exception { | |
| 229 | 229 | // 校验存在 |
| 230 | 230 | this.validateFileConfigExists(id); |
| 231 | 231 | // 上传文件 | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
| ... | ... | @@ -26,14 +26,14 @@ public interface FileService { |
| 26 | 26 | * @param content 文件内容 |
| 27 | 27 | * @return 文件路径 |
| 28 | 28 | */ |
| 29 | - String createFile(String path, byte[] content); | |
| 29 | + String createFile(String path, byte[] content) throws Exception; | |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * 删除文件 |
| 33 | 33 | * |
| 34 | 34 | * @param id 编号 |
| 35 | 35 | */ |
| 36 | - void deleteFile(Long id); | |
| 36 | + void deleteFile(Long id) throws Exception; | |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * 获得文件内容 |
| ... | ... | @@ -42,6 +42,6 @@ public interface FileService { |
| 42 | 42 | * @param path 文件路径 |
| 43 | 43 | * @return 文件内容 |
| 44 | 44 | */ |
| 45 | - byte[] getFileContent(Long configId, String path); | |
| 45 | + byte[] getFileContent(Long configId, String path) throws Exception; | |
| 46 | 46 | |
| 47 | 47 | } | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
| ... | ... | @@ -35,7 +35,7 @@ public class FileServiceImpl implements FileService { |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | @Override |
| 38 | - public String createFile(String path, byte[] content) { | |
| 38 | + public String createFile(String path, byte[] content) throws Exception { | |
| 39 | 39 | // 上传到文件存储器 |
| 40 | 40 | FileClient client = fileConfigService.getMasterFileClient(); |
| 41 | 41 | Assert.notNull(client, "客户端(master) 不能为空"); |
| ... | ... | @@ -53,7 +53,7 @@ public class FileServiceImpl implements FileService { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | @Override |
| 56 | - public void deleteFile(Long id) { | |
| 56 | + public void deleteFile(Long id) throws Exception { | |
| 57 | 57 | // 校验存在 |
| 58 | 58 | FileDO file = this.validateFileExists(id); |
| 59 | 59 | |
| ... | ... | @@ -75,7 +75,7 @@ public class FileServiceImpl implements FileService { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | @Override |
| 78 | - public byte[] getFileContent(Long configId, String path) { | |
| 78 | + public byte[] getFileContent(Long configId, String path) throws Exception { | |
| 79 | 79 | FileClient client = fileConfigService.getFileClient(configId); |
| 80 | 80 | Assert.notNull(client, "客户端({}) 不能为空", configId); |
| 81 | 81 | return client.getContent(path); | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java
| ... | ... | @@ -228,7 +228,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest { |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | @Test |
| 231 | - public void testFileConfig() { | |
| 231 | + public void testFileConfig() throws Exception { | |
| 232 | 232 | // mock 数据 |
| 233 | 233 | FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false); |
| 234 | 234 | fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据 | ... | ... |
yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
| ... | ... | @@ -70,7 +70,7 @@ public class FileServiceTest extends BaseDbUnitTest { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | @Test |
| 73 | - public void testCreateFile_success() { | |
| 73 | + public void testCreateFile_success() throws Exception { | |
| 74 | 74 | // 准备参数 |
| 75 | 75 | String path = randomString(); |
| 76 | 76 | byte[] content = ResourceUtil.readBytes("file/erweima.jpg"); |
| ... | ... | @@ -95,7 +95,7 @@ public class FileServiceTest extends BaseDbUnitTest { |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | @Test |
| 98 | - public void testDeleteFile_success() { | |
| 98 | + public void testDeleteFile_success() throws Exception { | |
| 99 | 99 | // mock 数据 |
| 100 | 100 | FileDO dbFile = randomPojo(FileDO.class, o -> o.setConfigId(10L).setPath("tudou.jpg")); |
| 101 | 101 | fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据 |
| ... | ... | @@ -123,7 +123,7 @@ public class FileServiceTest extends BaseDbUnitTest { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | @Test |
| 126 | - public void testGetFileContent() { | |
| 126 | + public void testGetFileContent() throws Exception { | |
| 127 | 127 | // 准备参数 |
| 128 | 128 | Long configId = 10L; |
| 129 | 129 | String path = "tudou.jpg"; | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java
| ... | ... | @@ -16,9 +16,8 @@ import org.springframework.web.multipart.MultipartFile; |
| 16 | 16 | |
| 17 | 17 | import javax.annotation.Resource; |
| 18 | 18 | import javax.validation.Valid; |
| 19 | -import java.io.IOException; | |
| 20 | 19 | |
| 21 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*; | |
| 20 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 23 | 22 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 24 | 23 | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY; |
| ... | ... | @@ -44,7 +43,7 @@ public class AppUserController { |
| 44 | 43 | @PutMapping("/update-avatar") |
| 45 | 44 | @ApiOperation("修改用户头像") |
| 46 | 45 | @PreAuthenticated |
| 47 | - public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | |
| 46 | + public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { | |
| 48 | 47 | if (file.isEmpty()) { |
| 49 | 48 | throw exception(FILE_IS_EMPTY); |
| 50 | 49 | } | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java
| ... | ... | @@ -60,7 +60,7 @@ public interface MemberUserService { |
| 60 | 60 | * @param inputStream 头像文件 |
| 61 | 61 | * @return 头像url |
| 62 | 62 | */ |
| 63 | - String updateUserAvatar(Long userId, InputStream inputStream); | |
| 63 | + String updateUserAvatar(Long userId, InputStream inputStream) throws Exception; | |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * 修改手机 | ... | ... |
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
| ... | ... | @@ -100,7 +100,7 @@ public class MemberUserServiceImpl implements MemberUserService { |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | @Override |
| 103 | - public String updateUserAvatar(Long userId, InputStream avatarFile) { | |
| 103 | + public String updateUserAvatar(Long userId, InputStream avatarFile) throws Exception { | |
| 104 | 104 | this.checkUserExists(userId); |
| 105 | 105 | // 创建文件 |
| 106 | 106 | String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); | ... | ... |
yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImplTest.java
| ... | ... | @@ -74,7 +74,7 @@ public class MemberUserServiceImplTest extends BaseDbAndRedisUnitTest { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | @Test |
| 77 | - public void testUpdateAvatar_success(){ | |
| 77 | + public void testUpdateAvatar_success() throws Exception { | |
| 78 | 78 | // mock 数据 |
| 79 | 79 | MemberUserDO dbUser = randomUserDO(); |
| 80 | 80 | userMapper.insert(dbUser); | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
| ... | ... | @@ -29,7 +29,6 @@ import org.springframework.web.multipart.MultipartFile; |
| 29 | 29 | |
| 30 | 30 | import javax.annotation.Resource; |
| 31 | 31 | import javax.validation.Valid; |
| 32 | -import java.io.IOException; | |
| 33 | 32 | import java.util.List; |
| 34 | 33 | |
| 35 | 34 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -99,7 +98,7 @@ public class UserProfileController { |
| 99 | 98 | |
| 100 | 99 | @PutMapping("/update-avatar") |
| 101 | 100 | @ApiOperation("上传用户个人头像") |
| 102 | - public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException { | |
| 101 | + public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception { | |
| 103 | 102 | if (file.isEmpty()) { |
| 104 | 103 | throw ServiceExceptionUtil.exception(FILE_IS_EMPTY); |
| 105 | 104 | } | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
| ... | ... | @@ -64,7 +64,7 @@ public interface AdminUserService { |
| 64 | 64 | * @param id 用户 id |
| 65 | 65 | * @param avatarFile 头像文件 |
| 66 | 66 | */ |
| 67 | - String updateUserAvatar(Long id, InputStream avatarFile); | |
| 67 | + String updateUserAvatar(Long id, InputStream avatarFile) throws Exception; | |
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * 修改密码 | ... | ... |
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -118,7 +118,7 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | @Override |
| 121 | - public String updateUserAvatar(Long id, InputStream avatarFile) { | |
| 121 | + public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception { | |
| 122 | 122 | this.checkUserExists(id); |
| 123 | 123 | // 存储文件 |
| 124 | 124 | String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile)); | ... | ... |
yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java
| ... | ... | @@ -196,7 +196,7 @@ public class UserServiceImplTest extends BaseDbUnitTest { |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | @Test |
| 199 | - public void testUpdateUserAvatar_success() { | |
| 199 | + public void testUpdateUserAvatar_success() throws Exception { | |
| 200 | 200 | // mock 数据 |
| 201 | 201 | AdminUserDO dbUser = randomAdminUserDO(); |
| 202 | 202 | userMapper.insert(dbUser); | ... | ... |
yudao-ui-admin/src/views/infra/fileConfig/index.vue
| ... | ... | @@ -109,9 +109,6 @@ |
| 109 | 109 | <el-form-item v-if="form.storage === 20" label="节点地址" prop="config.endpoint"> |
| 110 | 110 | <el-input v-model="form.config.endpoint" placeholder="请输入节点地址" /> |
| 111 | 111 | </el-form-item> |
| 112 | - <el-form-item v-if="form.storage === 20" label="区域" prop="config.region"> | |
| 113 | - <el-input v-model="form.config.region" placeholder="请输入区域" /> | |
| 114 | - </el-form-item> | |
| 115 | 112 | <el-form-item v-if="form.storage === 20" label="存储 bucket" prop="config.bucket"> |
| 116 | 113 | <el-input v-model="form.config.bucket" placeholder="请输入 bucket" /> |
| 117 | 114 | </el-form-item> |
| ... | ... | @@ -190,7 +187,6 @@ export default { |
| 190 | 187 | password: [{ required: true, message: "密码不能为空", trigger: "blur" }], |
| 191 | 188 | mode: [{ required: true, message: "连接模式不能为空", trigger: "change" }], |
| 192 | 189 | endpoint: [{ required: true, message: "节点地址不能为空", trigger: "blur" }], |
| 193 | - region: [{ required: true, message: "区域名不能为空", trigger: "blur" }], | |
| 194 | 190 | bucket: [{ required: true, message: "存储 bucket 不能为空", trigger: "blur" }], |
| 195 | 191 | accessKey: [{ required: true, message: "accessKey 不能为空", trigger: "blur" }], |
| 196 | 192 | accessSecret: [{ required: true, message: "accessSecret 不能为空", trigger: "blur" }], | ... | ... |