Pre Merge pull request !1344 from 王祁/master-jdk17
This commit is contained in:
commit
b0c22fa7dc
|
@ -62,7 +62,7 @@ public class FileConfigDO extends BaseDO {
|
||||||
private Boolean master;
|
private Boolean master;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付渠道配置
|
* 文件存储客户端配置
|
||||||
*/
|
*/
|
||||||
@TableField(typeHandler = FileClientConfigTypeHandler.class)
|
@TableField(typeHandler = FileClientConfigTypeHandler.class)
|
||||||
private FileClientConfig config;
|
private FileClientConfig config;
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class DBFileClient extends AbstractFileClient<DBFileClientConfig> {
|
||||||
.setPath(path).setContent(content);
|
.setPath(path).setContent(content);
|
||||||
fileContentMapper.insert(contentDO);
|
fileContentMapper.insert(contentDO);
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
|
if (config.getUseRelativePath()){
|
||||||
|
// 如果是 相对路径,则拼接相对路径前缀
|
||||||
|
return super.formatFileUrl(config.getRelativePathPrefix(), path);
|
||||||
|
}
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package cn.iocoder.yudao.module.infra.framework.file.core.client.db;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.db;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基于 DB 存储的文件客户端的配置类
|
* 基于 DB 存储的文件客户端的配置类
|
||||||
|
@ -14,11 +12,18 @@ import jakarta.validation.constraints.NotEmpty;
|
||||||
@Data
|
@Data
|
||||||
public class DBFileClientConfig implements FileClientConfig {
|
public class DBFileClientConfig implements FileClientConfig {
|
||||||
|
|
||||||
|
@NotNull(message = "是否使用相对路径不能为空")
|
||||||
|
private Boolean useRelativePath = false;
|
||||||
|
|
||||||
|
|
||||||
|
private String relativePathPrefix = "/file";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名
|
* 自定义域名
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "domain 不能为空")
|
// TODO 王祁 20250515 这里看如何做校验?当useRelativePath为true时,只校验relativePath,否则只校验domain,还是说在前端做
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
// @NotEmpty(message = "domain 不能为空")
|
||||||
|
// @URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,10 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||||
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
throw new FtpException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
||||||
}
|
}
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
|
if (config.getUseRelativePath()){
|
||||||
|
// 如果是 相对路径,则拼接相对路径前缀
|
||||||
|
return super.formatFileUrl(config.getRelativePathPrefix(), path);
|
||||||
|
}
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,18 @@ public class FtpFileClientConfig implements FileClientConfig {
|
||||||
@NotEmpty(message = "基础路径不能为空")
|
@NotEmpty(message = "基础路径不能为空")
|
||||||
private String basePath;
|
private String basePath;
|
||||||
|
|
||||||
|
@NotNull(message = "是否使用相对路径不能为空")
|
||||||
|
private Boolean useRelativePath = false;
|
||||||
|
|
||||||
|
|
||||||
|
private String relativePathPrefix = "/file";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名
|
* 自定义域名
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "domain 不能为空")
|
// TODO 王祁 20250515 这里看如何做校验?当useRelativePath为true时,只校验relativePath,否则只校验domain,还是说在前端做
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
// @NotEmpty(message = "domain 不能为空")
|
||||||
|
// @URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,10 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||||
String filePath = getFilePath(path);
|
String filePath = getFilePath(path);
|
||||||
FileUtil.writeBytes(content, filePath);
|
FileUtil.writeBytes(content, filePath);
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
|
if (config.getUseRelativePath()){
|
||||||
|
// 如果是 相对路径,则拼接相对路径前缀
|
||||||
|
return super.formatFileUrl(config.getRelativePathPrefix(), path);
|
||||||
|
}
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.iocoder.yudao.module.infra.framework.file.core.client.local;
|
package cn.iocoder.yudao.module.infra.framework.file.core.client.local;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
|
@ -20,11 +21,18 @@ public class LocalFileClientConfig implements FileClientConfig {
|
||||||
@NotEmpty(message = "基础路径不能为空")
|
@NotEmpty(message = "基础路径不能为空")
|
||||||
private String basePath;
|
private String basePath;
|
||||||
|
|
||||||
|
@NotNull(message = "是否使用相对路径不能为空")
|
||||||
|
private Boolean useRelativePath = false;
|
||||||
|
|
||||||
|
|
||||||
|
private String relativePathPrefix = "/file";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名
|
* 自定义域名
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "domain 不能为空")
|
// TODO 王祁 20250515 这里看如何做校验?当useRelativePath为true时,只校验relativePath,否则只校验domain,还是说在前端做
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
// @NotEmpty(message = "domain 不能为空")
|
||||||
|
// @URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,10 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||||
// 上传文件
|
// 上传文件
|
||||||
client.putObject(putRequest, RequestBody.fromBytes(content));
|
client.putObject(putRequest, RequestBody.fromBytes(content));
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
|
if (config.getUseRelativePath()){
|
||||||
|
// 如果是 相对路径,则拼接相对路径前缀
|
||||||
|
return config.getRelativePathPrefix() + "/" + path;
|
||||||
|
}
|
||||||
return config.getDomain() + "/" + path;
|
return config.getDomain() + "/" + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.infra.framework.file.core.client.s3;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.hibernate.validator.constraints.URL;
|
import org.hibernate.validator.constraints.URL;
|
||||||
|
|
||||||
|
@ -33,6 +34,13 @@ public class S3FileClientConfig implements FileClientConfig {
|
||||||
*/
|
*/
|
||||||
@NotNull(message = "endpoint 不能为空")
|
@NotNull(message = "endpoint 不能为空")
|
||||||
private String endpoint;
|
private String endpoint;
|
||||||
|
|
||||||
|
@NotNull(message = "是否使用相对路径不能为空")
|
||||||
|
private Boolean useRelativePath = false;
|
||||||
|
|
||||||
|
|
||||||
|
private String relativePathPrefix = "/file";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名
|
* 自定义域名
|
||||||
* 1. MinIO:通过 Nginx 配置
|
* 1. MinIO:通过 Nginx 配置
|
||||||
|
@ -42,7 +50,9 @@ public class S3FileClientConfig implements FileClientConfig {
|
||||||
* 5. 华为云:https://support.huaweicloud.com/usermanual-obs/obs_03_0032.html
|
* 5. 华为云:https://support.huaweicloud.com/usermanual-obs/obs_03_0032.html
|
||||||
* 6. 火山云:https://www.volcengine.com/docs/6349/128983
|
* 6. 火山云:https://www.volcengine.com/docs/6349/128983
|
||||||
*/
|
*/
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
// TODO 王祁 20250515 这里看如何做校验?当useRelativePath为true时,只校验relativePath,否则只校验domain,还是说在前端做
|
||||||
|
// @NotEmpty(message = "domain 不能为空")
|
||||||
|
// @URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
/**
|
/**
|
||||||
* 存储 Bucket
|
* 存储 Bucket
|
||||||
|
|
|
@ -35,6 +35,10 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||||
sftp.mkDirs(FileUtil.getParent(filePath, 1)); // 需要创建父目录,不然会报错
|
sftp.mkDirs(FileUtil.getParent(filePath, 1)); // 需要创建父目录,不然会报错
|
||||||
sftp.upload(filePath, file);
|
sftp.upload(filePath, file);
|
||||||
// 拼接返回路径
|
// 拼接返回路径
|
||||||
|
if (config.getUseRelativePath()){
|
||||||
|
// 如果是 相对路径,则拼接相对路径前缀
|
||||||
|
return super.formatFileUrl(config.getRelativePathPrefix(), path);
|
||||||
|
}
|
||||||
return super.formatFileUrl(config.getDomain(), path);
|
return super.formatFileUrl(config.getDomain(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,17 @@ public class SftpFileClientConfig implements FileClientConfig {
|
||||||
@NotEmpty(message = "基础路径不能为空")
|
@NotEmpty(message = "基础路径不能为空")
|
||||||
private String basePath;
|
private String basePath;
|
||||||
|
|
||||||
|
@NotNull(message = "是否使用相对路径不能为空")
|
||||||
|
private Boolean useRelativePath = false;
|
||||||
|
|
||||||
|
private String relativePathPrefix = "/file";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名
|
* 自定义域名
|
||||||
*/
|
*/
|
||||||
@NotEmpty(message = "domain 不能为空")
|
// TODO 王祁 20250515 这里看如何做校验?当useRelativePath为true时,只校验relativePath,否则只校验domain,还是说在前端做
|
||||||
@URL(message = "domain 必须是 URL 格式")
|
// @NotEmpty(message = "domain 不能为空")
|
||||||
|
// @URL(message = "domain 必须是 URL 格式")
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue