From d5716d661fe5223cfad8d1e101eb774f6939903d Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 27 Jan 2024 22:43:11 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E9=83=A8?= =?UTF-8?q?=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 Sonar 扫描问题 --- .../service/impl/StorageServiceImpl.java | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java index 48621b11..41895c8e 100644 --- a/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java +++ b/continew-admin-system/src/main/java/top/charles7c/continew/admin/system/service/impl/StorageServiceImpl.java @@ -118,38 +118,35 @@ public class StorageServiceImpl extends BaseServiceImpl { - ValidationUtils.throwIfBlank(bucketName, "存储路径不能为空"); - ValidationUtils.throwIfBlank(domain, "自定义域名不能为空"); - ValidationUtils.throwIf(!URLUtils.isHttpUrl(domain), "自定义域名格式错误"); - req.setBucketName(StrUtil.appendIfMissing(bucketName - .replace(StringConstants.BACKSLASH, StringConstants.SLASH), StringConstants.SLASH)); - FileStorageProperties.LocalPlusConfig config = new FileStorageProperties.LocalPlusConfig(); - config.setPlatform(req.getCode()); - config.setStoragePath(bucketName); - fileStorageList.addAll(FileStorageServiceBuilder.buildLocalPlusFileStorage(Collections - .singletonList(config))); - SpringWebUtils.registerResourceHandler(MapUtil.of(URLUtil.url(req.getDomain()).getPath(), bucketName)); - } - case S3 -> { - String accessKey = req.getAccessKey(); - String secretKey = req.getSecretKey(); - String endpoint = req.getEndpoint(); - ValidationUtils.throwIfBlank(accessKey, "访问密钥不能为空"); - ValidationUtils.throwIfBlank(secretKey, "私有密钥不能为空"); - ValidationUtils.throwIfBlank(endpoint, "终端节点不能为空"); - ValidationUtils.throwIfBlank(bucketName, "桶名称不能为空"); - FileStorageProperties.AmazonS3Config config = new FileStorageProperties.AmazonS3Config(); - config.setPlatform(req.getCode()); - config.setAccessKey(accessKey); - config.setSecretKey(secretKey); - config.setEndPoint(endpoint); - config.setBucketName(bucketName); - config.setDomain(domain); - fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections - .singletonList(config), null)); - } + if (StorageTypeEnum.LOCAL.equals(type)) { + ValidationUtils.throwIfBlank(bucketName, "存储路径不能为空"); + ValidationUtils.throwIfBlank(domain, "自定义域名不能为空"); + ValidationUtils.throwIf(!URLUtils.isHttpUrl(domain), "自定义域名格式错误"); + req.setBucketName(StrUtil.appendIfMissing(bucketName + .replace(StringConstants.BACKSLASH, StringConstants.SLASH), StringConstants.SLASH)); + FileStorageProperties.LocalPlusConfig config = new FileStorageProperties.LocalPlusConfig(); + config.setPlatform(req.getCode()); + config.setStoragePath(bucketName); + fileStorageList.addAll(FileStorageServiceBuilder.buildLocalPlusFileStorage(Collections + .singletonList(config))); + SpringWebUtils.registerResourceHandler(MapUtil.of(URLUtil.url(req.getDomain()).getPath(), bucketName)); + } else if (StorageTypeEnum.S3.equals(type)) { + String accessKey = req.getAccessKey(); + String secretKey = req.getSecretKey(); + String endpoint = req.getEndpoint(); + ValidationUtils.throwIfBlank(accessKey, "访问密钥不能为空"); + ValidationUtils.throwIfBlank(secretKey, "私有密钥不能为空"); + ValidationUtils.throwIfBlank(endpoint, "终端节点不能为空"); + ValidationUtils.throwIfBlank(bucketName, "桶名称不能为空"); + FileStorageProperties.AmazonS3Config config = new FileStorageProperties.AmazonS3Config(); + config.setPlatform(req.getCode()); + config.setAccessKey(accessKey); + config.setSecretKey(secretKey); + config.setEndPoint(endpoint); + config.setBucketName(bucketName); + config.setDomain(domain); + fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections + .singletonList(config), null)); } }