mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-08 12:57:13 +08:00
fix(system/storage): 修复对象存储域名配置
This commit is contained in:
@@ -16,9 +16,11 @@
|
||||
|
||||
package top.continew.admin.system.enums;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import top.continew.admin.common.constant.RegexConstants;
|
||||
import top.continew.admin.system.model.req.StorageReq;
|
||||
import top.continew.admin.system.validation.ValidationGroup;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
@@ -62,8 +64,8 @@ public enum StorageTypeEnum implements BaseEnum<Integer> {
|
||||
@Override
|
||||
public void validate(StorageReq req) {
|
||||
ValidationUtils.validate(req, ValidationGroup.Storage.OSS.class);
|
||||
ValidationUtils.throwIf(StrUtil.isNotBlank(req.getDomain()) && !URLUtils.isHttpUrl(req
|
||||
.getDomain()), "域名格式不正确");
|
||||
ValidationUtils.throwIf(StrUtil.isNotBlank(req.getDomain()) && !ReUtil
|
||||
.isMatch(RegexConstants.HTTP_DOMAIN_URL, req.getDomain()), "域名格式不正确");
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -48,7 +48,6 @@ import top.continew.starter.core.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.crud.service.BaseServiceImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -91,65 +90,13 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo upload(MultipartFile file, String parentPath, String storageCode) throws IOException {
|
||||
// 校验文件格式
|
||||
String extName = FileNameUtil.extName(file.getOriginalFilename());
|
||||
return getFileInfo(file, parentPath, storageCode, extName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件并返回上传后的文件信息
|
||||
*
|
||||
* @param file
|
||||
* @param parentPath
|
||||
* @param storageCode
|
||||
* @param extName
|
||||
* @return
|
||||
*/
|
||||
private FileInfo getFileInfo(Object file, String parentPath, String storageCode, String extName) {
|
||||
List<String> allExtensions = FileTypeEnum.getAllExtensions();
|
||||
CheckUtils.throwIf(!allExtensions.contains(extName), "不支持的文件类型,仅支持 {} 格式的文件", String
|
||||
.join(StringConstants.COMMA, allExtensions));
|
||||
// 构建上传预处理对象
|
||||
StorageDO storage = storageService.getByCode(storageCode);
|
||||
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(storage.getStatus()), "请先启用存储 [{}]", storage.getCode());
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(file)
|
||||
.setPlatform(storage.getCode())
|
||||
.setHashCalculatorSha256(true)
|
||||
.putAttr(ClassUtil.getClassName(StorageDO.class, false), storage)
|
||||
.setPath(this.pretreatmentPath(parentPath));
|
||||
// 图片文件生成缩略图
|
||||
if (FileTypeEnum.IMAGE.getExtensions().contains(extName)) {
|
||||
uploadPretreatment.setIgnoreThumbnailException(true, true);
|
||||
uploadPretreatment.thumbnail(img -> img.size(100, 100));
|
||||
}
|
||||
uploadPretreatment.setProgressMonitor(new ProgressListener() {
|
||||
@Override
|
||||
public void start() {
|
||||
log.info("开始上传");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(long progressSize, Long allSize) {
|
||||
log.info("已上传 [{}],总大小 [{}]", progressSize, allSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
log.info("上传结束");
|
||||
}
|
||||
});
|
||||
// 创建父级目录
|
||||
this.createParentDir(parentPath, storage);
|
||||
// 上传
|
||||
return uploadPretreatment.upload();
|
||||
public FileInfo upload(MultipartFile file, String parentPath, String storageCode) {
|
||||
return this.upload(file, parentPath, storageCode, FileNameUtil.extName(file.getOriginalFilename()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo upload(File file, String parentPath, String storageCode) throws IOException {
|
||||
// 校验文件格式
|
||||
String extName = FileNameUtil.extName(file.getName());
|
||||
return getFileInfo(file, parentPath, storageCode, extName);
|
||||
public FileInfo upload(File file, String parentPath, String storageCode) {
|
||||
return this.upload(file, parentPath, storageCode, FileNameUtil.extName(file.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,6 +198,54 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件并返回上传后的文件信息
|
||||
*
|
||||
* @param file 文件
|
||||
* @param parentPath 上级目录
|
||||
* @param storageCode 存储引擎编码
|
||||
* @param extName 文件扩展名
|
||||
* @return 文件信息
|
||||
*/
|
||||
private FileInfo upload(Object file, String parentPath, String storageCode, String extName) {
|
||||
List<String> allExtensions = FileTypeEnum.getAllExtensions();
|
||||
CheckUtils.throwIf(!allExtensions.contains(extName), "不支持的文件类型,仅支持 {} 格式的文件", String
|
||||
.join(StringConstants.COMMA, allExtensions));
|
||||
// 构建上传预处理对象
|
||||
StorageDO storage = storageService.getByCode(storageCode);
|
||||
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(storage.getStatus()), "请先启用存储 [{}]", storage.getCode());
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(file)
|
||||
.setPlatform(storage.getCode())
|
||||
.setHashCalculatorSha256(true)
|
||||
.putAttr(ClassUtil.getClassName(StorageDO.class, false), storage)
|
||||
.setPath(this.pretreatmentPath(parentPath));
|
||||
// 图片文件生成缩略图
|
||||
if (FileTypeEnum.IMAGE.getExtensions().contains(extName)) {
|
||||
uploadPretreatment.setIgnoreThumbnailException(true, true);
|
||||
uploadPretreatment.thumbnail(img -> img.size(100, 100));
|
||||
}
|
||||
uploadPretreatment.setProgressMonitor(new ProgressListener() {
|
||||
@Override
|
||||
public void start() {
|
||||
log.info("开始上传");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(long progressSize, Long allSize) {
|
||||
log.info("已上传 [{}],总大小 [{}]", progressSize, allSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
log.info("上传结束");
|
||||
}
|
||||
});
|
||||
// 创建父级目录
|
||||
this.createParentDir(parentPath, storage);
|
||||
// 上传
|
||||
return uploadPretreatment.upload();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理路径
|
||||
*
|
||||
|
@@ -198,7 +198,6 @@ public class StorageServiceImpl extends BaseServiceImpl<StorageMapper, StorageDO
|
||||
config.setSecretKey(storage.getSecretKey());
|
||||
config.setEndPoint(storage.getEndpoint());
|
||||
config.setBucketName(storage.getBucketName());
|
||||
config.setDomain(StrUtil.emptyIfNull(storage.getDomain()));
|
||||
fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections
|
||||
.singletonList(config), null));
|
||||
}
|
||||
|
Reference in New Issue
Block a user