Browse Source

优化文件配置,去掉 region 的配置,通过自动识别

YunaiV 3 years ago
parent
commit
813069abf4
21 changed files with 28 additions and 43 deletions
  1. 0 6
      yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java
  2. 0 1
      yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java
  3. 2 2
      yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApi.java
  4. 1 2
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java
  5. 1 1
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.java
  6. 3 4
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java
  7. 1 1
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java
  8. 1 1
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
  9. 3 3
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileService.java
  10. 3 3
      yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
  11. 1 1
      yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImplTest.java
  12. 3 3
      yudao-module-infra/yudao-module-infra-impl/src/test/java/cn/iocoder/yudao/module/infra/service/file/FileServiceTest.java
  13. 2 3
      yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java
  14. 1 1
      yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java
  15. 1 1
      yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
  16. 1 1
      yudao-module-member/yudao-module-member-impl/src/test/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImplTest.java
  17. 1 2
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserProfileController.java
  18. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
  19. 1 1
      yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
  20. 1 1
      yudao-module-system/yudao-module-system-impl/src/test/java/cn/iocoder/yudao/module/system/service/user/UserServiceImplTest.java
  21. 0 4
      yudao-ui-admin/src/views/infra/fileConfig/index.vue

+ 0 - 6
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientConfig.java

@@ -40,12 +40,6 @@ public class S3FileClientConfig implements FileClientConfig {
      */
     @URL(message = "domain 必须是 URL 格式")
     private String domain;
-    /**
-     * 区域
-     */
-//    @NotNull(message = "region 不能为空")
-    @Deprecated
-    private String region;
     /**
      * 存储 Bucket
      */

+ 0 - 1
yudao-framework/yudao-spring-boot-starter-file/src/test/java/cn/iocoder/yudao/framework/file/core/client/s3/S3FileClientTest.java

@@ -21,7 +21,6 @@ public class S3FileClientTest {
         config.setDomain(null);
         // 默认 9000 endpoint
         config.setEndpoint("http://127.0.0.1:9000");
-        config.setRegion("us-east-1");
 
         // 执行上传
         testExecuteUpload(config);

+ 2 - 2
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 {
      * @param content 文件内容
      * @return 文件路径
      */
-   default String createFile(byte[] content) {
+   default String createFile(byte[] content) throws Exception {
        return createFile(IdUtil.fastUUID(), content);
    }
 
@@ -26,6 +26,6 @@ public interface FileApi {
      * @param content 文件内容
      * @return 文件路径
      */
-    String createFile(String path, byte[] content);
+    String createFile(String path, byte[] content) throws Exception;
 
 }

+ 1 - 2
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/api/file/FileApiImpl.java

@@ -1,6 +1,5 @@
 package cn.iocoder.yudao.module.infra.api.file;
 
-import cn.iocoder.yudao.module.infra.api.file.FileApi;
 import cn.iocoder.yudao.module.infra.service.file.FileService;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
@@ -20,7 +19,7 @@ public class FileApiImpl implements FileApi {
     private FileService fileService;
 
     @Override
-    public String createFile(String path, byte[] content) {
+    public String createFile(String path, byte[] content) throws Exception {
         return fileService.createFile(path, content);
     }
 

+ 1 - 1
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 {
     @GetMapping("/test")
     @ApiOperation("测试文件配置是否正确")
     @PreAuthorize("@ss.hasPermission('infra:file-config:query')")
-    public CommonResult<String> testFileConfig(@RequestParam("id") Long id) {
+    public CommonResult<String> testFileConfig(@RequestParam("id") Long id) throws Exception {
         String url = fileConfigService.testFileConfig(id);
         return success(url);
     }

+ 3 - 4
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;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
-import java.io.IOException;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
@@ -44,7 +43,7 @@ public class FileController {
             @ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
     })
     public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
-                                           @RequestParam("path") String path) throws IOException {
+                                           @RequestParam("path") String path) throws Exception {
         return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
     }
 
@@ -52,7 +51,7 @@ public class FileController {
     @ApiOperation("删除文件")
     @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
     @PreAuthorize("@ss.hasPermission('infra:file:delete')")
-    public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) {
+    public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) throws Exception {
         fileService.deleteFile(id);
         return success(true);
     }
@@ -65,7 +64,7 @@ public class FileController {
     })
     public void getFileContent(HttpServletResponse response,
                                @PathVariable("configId") Long configId,
-                               @PathVariable("path") String path) throws IOException {
+                               @PathVariable("path") String path) throws Exception {
         byte[] content = fileService.getFileContent(configId, path);
         if (content == null) {
             log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);

+ 1 - 1
yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigService.java

@@ -82,7 +82,7 @@ public interface FileConfigService {
      * @param id 编号
      * @return 文件 URL
      */
-    String testFileConfig(Long id);
+    String testFileConfig(Long id) throws Exception;
 
     /**
      * 获得指定编号的文件客户端

+ 1 - 1
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 {
     }
 
     @Override
-    public String testFileConfig(Long id) {
+    public String testFileConfig(Long id) throws Exception {
         // 校验存在
         this.validateFileConfigExists(id);
         // 上传文件

+ 3 - 3
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 {
      * @param content 文件内容
      * @return 文件路径
      */
-    String createFile(String path, byte[] content);
+    String createFile(String path, byte[] content) throws Exception;
 
     /**
      * 删除文件
      *
      * @param id 编号
      */
-    void deleteFile(Long id);
+    void deleteFile(Long id) throws Exception;
 
     /**
      * 获得文件内容
@@ -42,6 +42,6 @@ public interface FileService {
      * @param path 文件路径
      * @return 文件内容
      */
-    byte[] getFileContent(Long configId, String path);
+    byte[] getFileContent(Long configId, String path) throws Exception;
 
 }

+ 3 - 3
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 {
     }
 
     @Override
-    public String createFile(String path, byte[] content) {
+    public String createFile(String path, byte[] content) throws Exception {
         // 上传到文件存储器
         FileClient client = fileConfigService.getMasterFileClient();
         Assert.notNull(client, "客户端(master) 不能为空");
@@ -53,7 +53,7 @@ public class FileServiceImpl implements FileService {
     }
 
     @Override
-    public void deleteFile(Long id) {
+    public void deleteFile(Long id) throws Exception {
         // 校验存在
         FileDO file = this.validateFileExists(id);
 
@@ -75,7 +75,7 @@ public class FileServiceImpl implements FileService {
     }
 
     @Override
-    public byte[] getFileContent(Long configId, String path) {
+    public byte[] getFileContent(Long configId, String path) throws Exception {
         FileClient client = fileConfigService.getFileClient(configId);
         Assert.notNull(client, "客户端({}) 不能为空", configId);
         return client.getContent(path);

+ 1 - 1
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 {
     }
 
     @Test
-    public void testFileConfig() {
+    public void testFileConfig() throws Exception {
         // mock 数据
         FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false);
         fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据

+ 3 - 3
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 {
     }
 
     @Test
-    public void testCreateFile_success() {
+    public void testCreateFile_success() throws Exception {
         // 准备参数
         String path = randomString();
         byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
@@ -95,7 +95,7 @@ public class FileServiceTest extends BaseDbUnitTest {
     }
 
     @Test
-    public void testDeleteFile_success() {
+    public void testDeleteFile_success() throws Exception {
         // mock 数据
         FileDO dbFile = randomPojo(FileDO.class, o -> o.setConfigId(10L).setPath("tudou.jpg"));
         fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
@@ -123,7 +123,7 @@ public class FileServiceTest extends BaseDbUnitTest {
     }
 
     @Test
-    public void testGetFileContent() {
+    public void testGetFileContent() throws Exception {
         // 准备参数
         Long configId = 10L;
         String path = "tudou.jpg";

+ 2 - 3
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;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
-import java.io.IOException;
 
-import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.*;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
@@ -44,7 +43,7 @@ public class AppUserController {
     @PutMapping("/update-avatar")
     @ApiOperation("修改用户头像")
     @PreAuthenticated
-    public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
+    public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
         if (file.isEmpty()) {
             throw exception(FILE_IS_EMPTY);
         }

+ 1 - 1
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 {
      * @param inputStream 头像文件
      * @return 头像url
      */
-    String updateUserAvatar(Long userId, InputStream inputStream);
+    String updateUserAvatar(Long userId, InputStream inputStream) throws Exception;
 
     /**
      * 修改手机

+ 1 - 1
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 {
     }
 
     @Override
-    public String updateUserAvatar(Long userId, InputStream avatarFile) {
+    public String updateUserAvatar(Long userId, InputStream avatarFile) throws Exception {
         this.checkUserExists(userId);
         // 创建文件
         String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));

+ 1 - 1
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 {
     }
 
     @Test
-    public void testUpdateAvatar_success(){
+    public void testUpdateAvatar_success() throws Exception {
         // mock 数据
         MemberUserDO dbUser = randomUserDO();
         userMapper.insert(dbUser);

+ 1 - 2
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;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
-import java.io.IOException;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -99,7 +98,7 @@ public class UserProfileController {
 
     @PutMapping("/update-avatar")
     @ApiOperation("上传用户个人头像")
-    public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws IOException {
+    public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
         if (file.isEmpty()) {
             throw ServiceExceptionUtil.exception(FILE_IS_EMPTY);
         }

+ 1 - 1
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 {
      * @param id         用户 id
      * @param avatarFile 头像文件
      */
-    String updateUserAvatar(Long id, InputStream avatarFile);
+    String updateUserAvatar(Long id, InputStream avatarFile) throws Exception;
 
     /**
      * 修改密码

+ 1 - 1
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 {
     }
 
     @Override
-    public String updateUserAvatar(Long id, InputStream avatarFile) {
+    public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception {
         this.checkUserExists(id);
         // 存储文件
         String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));

+ 1 - 1
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 {
     }
 
     @Test
-    public void testUpdateUserAvatar_success() {
+    public void testUpdateUserAvatar_success() throws Exception {
         // mock 数据
         AdminUserDO dbUser = randomAdminUserDO();
         userMapper.insert(dbUser);

+ 0 - 4
yudao-ui-admin/src/views/infra/fileConfig/index.vue

@@ -109,9 +109,6 @@
         <el-form-item v-if="form.storage === 20" label="节点地址" prop="config.endpoint">
           <el-input v-model="form.config.endpoint" placeholder="请输入节点地址" />
         </el-form-item>
-        <el-form-item v-if="form.storage === 20" label="区域" prop="config.region">
-          <el-input v-model="form.config.region" placeholder="请输入区域" />
-        </el-form-item>
         <el-form-item v-if="form.storage === 20" label="存储 bucket" prop="config.bucket">
           <el-input v-model="form.config.bucket" placeholder="请输入 bucket" />
         </el-form-item>
@@ -190,7 +187,6 @@ export default {
           password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
           mode: [{ required: true, message: "连接模式不能为空", trigger: "change" }],
           endpoint: [{ required: true, message: "节点地址不能为空", trigger: "blur" }],
-          region: [{ required: true, message: "区域名不能为空", trigger: "blur" }],
           bucket: [{ required: true, message: "存储 bucket 不能为空", trigger: "blur" }],
           accessKey: [{ required: true, message: "accessKey 不能为空", trigger: "blur" }],
           accessSecret: [{ required: true, message: "accessSecret 不能为空", trigger: "blur" }],