mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-08 22:57:12 +08:00
fix(system/storage): 修复对象存储域名配置
This commit is contained in:
@@ -59,6 +59,11 @@ public class RegexConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String PACKAGE_NAME = "^(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*[a-zA-Z_][a-zA-Z0-9_]*$";
|
public static final String PACKAGE_NAME = "^(?:[a-zA-Z_][a-zA-Z0-9_]*\\.)*[a-zA-Z_][a-zA-Z0-9_]*$";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP 域名 URL 正则
|
||||||
|
*/
|
||||||
|
public static final String HTTP_DOMAIN_URL = "^(https?:\\/\\/)([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}(\\/[^\\s]*)?$";
|
||||||
|
|
||||||
private RegexConstants() {
|
private RegexConstants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -79,7 +79,8 @@ public class ContiNewAdminApplication implements ApplicationRunner {
|
|||||||
log.info("----------------------------------------------");
|
log.info("----------------------------------------------");
|
||||||
log.info("{} service started successfully.", projectProperties.getName());
|
log.info("{} service started successfully.", projectProperties.getName());
|
||||||
log.info("Profile: {}", SpringUtil.getProperty("spring.profiles.active"));
|
log.info("Profile: {}", SpringUtil.getProperty("spring.profiles.active"));
|
||||||
log.info("项目版本: v{} (ContiNew Starter: v{})", projectProperties.getVersion(), SpringUtil.getProperty("project.starter"));
|
log.info("项目版本: v{} (ContiNew Starter: v{})", projectProperties.getVersion(), SpringUtil
|
||||||
|
.getProperty("project.starter"));
|
||||||
log.info("API 地址: {}", baseUrl);
|
log.info("API 地址: {}", baseUrl);
|
||||||
Knife4jProperties knife4jProperties = SpringUtil.getBean(Knife4jProperties.class);
|
Knife4jProperties knife4jProperties = SpringUtil.getBean(Knife4jProperties.class);
|
||||||
if (!knife4jProperties.isProduction()) {
|
if (!knife4jProperties.isProduction()) {
|
||||||
|
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package top.continew.admin.system.enums;
|
package top.continew.admin.system.enums;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ReUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import top.continew.admin.common.constant.RegexConstants;
|
||||||
import top.continew.admin.system.model.req.StorageReq;
|
import top.continew.admin.system.model.req.StorageReq;
|
||||||
import top.continew.admin.system.validation.ValidationGroup;
|
import top.continew.admin.system.validation.ValidationGroup;
|
||||||
import top.continew.starter.core.constant.StringConstants;
|
import top.continew.starter.core.constant.StringConstants;
|
||||||
@@ -62,8 +64,8 @@ public enum StorageTypeEnum implements BaseEnum<Integer> {
|
|||||||
@Override
|
@Override
|
||||||
public void validate(StorageReq req) {
|
public void validate(StorageReq req) {
|
||||||
ValidationUtils.validate(req, ValidationGroup.Storage.OSS.class);
|
ValidationUtils.validate(req, ValidationGroup.Storage.OSS.class);
|
||||||
ValidationUtils.throwIf(StrUtil.isNotBlank(req.getDomain()) && !URLUtils.isHttpUrl(req
|
ValidationUtils.throwIf(StrUtil.isNotBlank(req.getDomain()) && !ReUtil
|
||||||
.getDomain()), "域名格式不正确");
|
.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 top.continew.starter.extension.crud.service.BaseServiceImpl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -91,65 +90,13 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileInfo upload(MultipartFile file, String parentPath, String storageCode) throws IOException {
|
public FileInfo upload(MultipartFile file, String parentPath, String storageCode) {
|
||||||
// 校验文件格式
|
return this.upload(file, parentPath, storageCode, FileNameUtil.extName(file.getOriginalFilename()));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileInfo upload(File file, String parentPath, String storageCode) throws IOException {
|
public FileInfo upload(File file, String parentPath, String storageCode) {
|
||||||
// 校验文件格式
|
return this.upload(file, parentPath, storageCode, FileNameUtil.extName(file.getName()));
|
||||||
String extName = FileNameUtil.extName(file.getName());
|
|
||||||
return getFileInfo(file, parentPath, storageCode, extName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.setSecretKey(storage.getSecretKey());
|
||||||
config.setEndPoint(storage.getEndpoint());
|
config.setEndPoint(storage.getEndpoint());
|
||||||
config.setBucketName(storage.getBucketName());
|
config.setBucketName(storage.getBucketName());
|
||||||
config.setDomain(StrUtil.emptyIfNull(storage.getDomain()));
|
|
||||||
fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections
|
fileStorageList.addAll(FileStorageServiceBuilder.buildAmazonS3FileStorage(Collections
|
||||||
.singletonList(config), null));
|
.singletonList(config), null));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user