Merge branch 'dev' into test
This commit is contained in:
@@ -29,6 +29,9 @@ import java.time.Duration;
|
|||||||
* @author ZT
|
* @author ZT
|
||||||
*/
|
*/
|
||||||
public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||||
|
|
||||||
|
private static final Duration DEFAULT_PRESIGNED_EXPIRATION = Duration.ofHours(24);
|
||||||
|
private static final String PRESIGN_EXPIRE_SECONDS_PROPERTY = "zt.file.download-expire-seconds";
|
||||||
/**
|
/**
|
||||||
* 生成临时下载地址(预签名下载 URL)
|
* 生成临时下载地址(预签名下载 URL)
|
||||||
* @param path 文件路径
|
* @param path 文件路径
|
||||||
@@ -37,17 +40,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getPresignedDownloadUrl(String path, Duration expiration) {
|
public String getPresignedDownloadUrl(String path, Duration expiration) {
|
||||||
Duration realExpiration = expiration;
|
Duration realExpiration = expiration != null ? expiration : resolveDefaultExpiration();
|
||||||
if (realExpiration == null) {
|
|
||||||
long expireSeconds = 30; // 默认 30 秒
|
|
||||||
try {
|
|
||||||
String val = SpringUtils.getProperty("zt.file.download-expire-seconds");
|
|
||||||
if (val != null && !val.isEmpty()) {
|
|
||||||
expireSeconds = Long.parseLong(val);
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
realExpiration = Duration.ofSeconds(expireSeconds);
|
|
||||||
}
|
|
||||||
if (path == null){
|
if (path == null){
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
}
|
}
|
||||||
@@ -135,10 +128,25 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FilePresignedUrlRespDTO getPresignedObjectUrl(String path) {
|
public FilePresignedUrlRespDTO getPresignedObjectUrl(String path) {
|
||||||
Duration expiration = Duration.ofHours(24);
|
Duration expiration = resolveDefaultExpiration();
|
||||||
return new FilePresignedUrlRespDTO(getPresignedUrl(path, expiration), config.getDomain() + "/" + path);
|
return new FilePresignedUrlRespDTO(getPresignedUrl(path, expiration), config.getDomain() + "/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Duration resolveDefaultExpiration() {
|
||||||
|
String propertyValue = SpringUtils.getProperty(PRESIGN_EXPIRE_SECONDS_PROPERTY);
|
||||||
|
if (StringUtils.isNotEmpty(propertyValue)) {
|
||||||
|
try {
|
||||||
|
long seconds = Long.parseLong(propertyValue);
|
||||||
|
if (seconds > 0) {
|
||||||
|
return Duration.ofSeconds(seconds);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
// ignore invalid config values and fall back to default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DEFAULT_PRESIGNED_EXPIRATION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成动态的预签名上传 URL
|
* 生成动态的预签名上传 URL
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ zt:
|
|||||||
key: "0123456789abcdef0123456789abcdef"
|
key: "0123456789abcdef0123456789abcdef"
|
||||||
# 附件预览
|
# 附件预览
|
||||||
kkfile: "http://172.16.46.63:30012/onlinePreview?url="
|
kkfile: "http://172.16.46.63:30012/onlinePreview?url="
|
||||||
|
file:
|
||||||
|
download-expire-seconds: 86400 # 对象存储预签名地址默认有效期(秒)
|
||||||
info:
|
info:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
base-package: com.zt.plat.module.infra
|
base-package: com.zt.plat.module.infra
|
||||||
|
|||||||
@@ -257,6 +257,8 @@ zt:
|
|||||||
info:
|
info:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
base-package: com.zt.plat
|
base-package: com.zt.plat
|
||||||
|
file:
|
||||||
|
download-expire-seconds: 86400 # 对象存储预签名地址默认有效期(秒)
|
||||||
web:
|
web:
|
||||||
admin-ui:
|
admin-ui:
|
||||||
url: http://dashboard.zt.iocoder.cn # Admin 管理后台 UI 的地址
|
url: http://dashboard.zt.iocoder.cn # Admin 管理后台 UI 的地址
|
||||||
|
|||||||
Reference in New Issue
Block a user