refactor: 优化部分代码
修复 Sonar 扫描问题
This commit is contained in:
parent
bcdcf888fb
commit
d5716d661f
@ -118,38 +118,35 @@ public class StorageServiceImpl extends BaseServiceImpl<StorageMapper, StorageDO
|
|||||||
String bucketName = req.getBucketName();
|
String bucketName = req.getBucketName();
|
||||||
String domain = req.getDomain();
|
String domain = req.getDomain();
|
||||||
StorageTypeEnum type = req.getType();
|
StorageTypeEnum type = req.getType();
|
||||||
switch (type) {
|
if (StorageTypeEnum.LOCAL.equals(type)) {
|
||||||
case LOCAL -> {
|
ValidationUtils.throwIfBlank(bucketName, "存储路径不能为空");
|
||||||
ValidationUtils.throwIfBlank(bucketName, "存储路径不能为空");
|
ValidationUtils.throwIfBlank(domain, "自定义域名不能为空");
|
||||||
ValidationUtils.throwIfBlank(domain, "自定义域名不能为空");
|
ValidationUtils.throwIf(!URLUtils.isHttpUrl(domain), "自定义域名格式错误");
|
||||||
ValidationUtils.throwIf(!URLUtils.isHttpUrl(domain), "自定义域名格式错误");
|
req.setBucketName(StrUtil.appendIfMissing(bucketName
|
||||||
req.setBucketName(StrUtil.appendIfMissing(bucketName
|
.replace(StringConstants.BACKSLASH, StringConstants.SLASH), StringConstants.SLASH));
|
||||||
.replace(StringConstants.BACKSLASH, StringConstants.SLASH), StringConstants.SLASH));
|
FileStorageProperties.LocalPlusConfig config = new FileStorageProperties.LocalPlusConfig();
|
||||||
FileStorageProperties.LocalPlusConfig config = new FileStorageProperties.LocalPlusConfig();
|
config.setPlatform(req.getCode());
|
||||||
config.setPlatform(req.getCode());
|
config.setStoragePath(bucketName);
|
||||||
config.setStoragePath(bucketName);
|
fileStorageList.addAll(FileStorageServiceBuilder.buildLocalPlusFileStorage(Collections
|
||||||
fileStorageList.addAll(FileStorageServiceBuilder.buildLocalPlusFileStorage(Collections
|
.singletonList(config)));
|
||||||
.singletonList(config)));
|
SpringWebUtils.registerResourceHandler(MapUtil.of(URLUtil.url(req.getDomain()).getPath(), bucketName));
|
||||||
SpringWebUtils.registerResourceHandler(MapUtil.of(URLUtil.url(req.getDomain()).getPath(), bucketName));
|
} else if (StorageTypeEnum.S3.equals(type)) {
|
||||||
}
|
String accessKey = req.getAccessKey();
|
||||||
case S3 -> {
|
String secretKey = req.getSecretKey();
|
||||||
String accessKey = req.getAccessKey();
|
String endpoint = req.getEndpoint();
|
||||||
String secretKey = req.getSecretKey();
|
ValidationUtils.throwIfBlank(accessKey, "访问密钥不能为空");
|
||||||
String endpoint = req.getEndpoint();
|
ValidationUtils.throwIfBlank(secretKey, "私有密钥不能为空");
|
||||||
ValidationUtils.throwIfBlank(accessKey, "访问密钥不能为空");
|
ValidationUtils.throwIfBlank(endpoint, "终端节点不能为空");
|
||||||
ValidationUtils.throwIfBlank(secretKey, "私有密钥不能为空");
|
ValidationUtils.throwIfBlank(bucketName, "桶名称不能为空");
|
||||||
ValidationUtils.throwIfBlank(endpoint, "终端节点不能为空");
|
FileStorageProperties.AmazonS3Config config = new FileStorageProperties.AmazonS3Config();
|
||||||
ValidationUtils.throwIfBlank(bucketName, "桶名称不能为空");
|
config.setPlatform(req.getCode());
|
||||||
FileStorageProperties.AmazonS3Config config = new FileStorageProperties.AmazonS3Config();
|
config.setAccessKey(accessKey);
|
||||||
config.setPlatform(req.getCode());
|
config.setSecretKey(secretKey);
|
||||||
config.setAccessKey(accessKey);
|
config.setEndPoint(endpoint);
|
||||||
config.setSecretKey(secretKey);
|
config.setBucketName(bucketName);
|
||||||
config.setEndPoint(endpoint);
|
config.setDomain(domain);
|
||||||
config.setBucketName(bucketName);
|
fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections
|
||||||
config.setDomain(domain);
|
.singletonList(config), null));
|
||||||
fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections
|
|
||||||
.singletonList(config), null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user