Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
hewencai
2025-11-10 10:41:48 +08:00
3 changed files with 24 additions and 12 deletions

View File

@@ -29,6 +29,9 @@ import java.time.Duration;
* @author ZT
*/
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
* @param path 文件路径
@@ -37,17 +40,7 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
*/
@Override
public String getPresignedDownloadUrl(String path, Duration expiration) {
Duration realExpiration = expiration;
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);
}
Duration realExpiration = expiration != null ? expiration : resolveDefaultExpiration();
if (path == null){
return StringUtils.EMPTY;
}
@@ -135,10 +128,25 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
@Override
public FilePresignedUrlRespDTO getPresignedObjectUrl(String path) {
Duration expiration = Duration.ofHours(24);
Duration expiration = resolveDefaultExpiration();
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
*

View File

@@ -148,6 +148,8 @@ zt:
key: "0123456789abcdef0123456789abcdef"
# 附件预览
kkfile: "http://172.16.46.63:30012/onlinePreview?url="
file:
download-expire-seconds: 86400 # 对象存储预签名地址默认有效期(秒)
info:
version: 1.0.0
base-package: com.zt.plat.module.infra

View File

@@ -257,6 +257,8 @@ zt:
info:
version: 1.0.0
base-package: com.zt.plat
file:
download-expire-seconds: 86400 # 对象存储预签名地址默认有效期(秒)
web:
admin-ui:
url: http://dashboard.zt.iocoder.cn # Admin 管理后台 UI 的地址