fix(project): 实现项目和任务实际开始结束日期的自动同步功能。
fix(file): 优化 S3 文件客户端的 URL 处理逻辑。
This commit is contained in:
@@ -114,9 +114,10 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||
|
||||
@Override
|
||||
public String presignGetUrl(String url, Integer expirationSeconds) {
|
||||
// 1. 将 url 转换为 path
|
||||
String path = StrUtil.removePrefix(url, config.getDomain() + "/");
|
||||
path = HttpUtils.decodeUtf8(HttpUtils.removeUrlQuery(path));
|
||||
// 1. 将入参转换为对象 key
|
||||
// - upload(...) 这里传进来的是原始 path(未编码),绝不能先 decode
|
||||
// - 历史记录 / 对外接口传进来的可能是完整 URL(可能已编码),这时才需要 decode
|
||||
String path = resolveObjectKey(url);
|
||||
|
||||
// 2.1 情况一:公开访问:无需签名
|
||||
// 考虑到老版本的兼容,所以必须是 config.getEnablePublicAccess() 为 false 时,才进行签名
|
||||
@@ -134,6 +135,23 @@ public class S3FileClient extends AbstractFileClient<S3FileClientConfig> {
|
||||
return signedUrl.toString();
|
||||
}
|
||||
|
||||
private String resolveObjectKey(String urlOrPath) {
|
||||
String cleaned = HttpUtils.removeUrlQuery(urlOrPath);
|
||||
if (!HttpUtil.isHttp(cleaned) && !HttpUtil.isHttps(cleaned)) {
|
||||
return cleaned;
|
||||
}
|
||||
|
||||
String path = StrUtil.removePrefix(cleaned, config.getDomain() + "/");
|
||||
if (StrUtil.equals(path, cleaned)) {
|
||||
URI uri = URI.create(cleaned);
|
||||
path = StrUtil.removePrefix(StrUtil.nullToEmpty(uri.getPath()), "/");
|
||||
if (Boolean.TRUE.equals(config.getEnablePathStyleAccess())) {
|
||||
path = StrUtil.removePrefix(path, config.getBucket() + "/");
|
||||
}
|
||||
}
|
||||
return HttpUtils.decodeUtf8(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 基于 bucket + endpoint 构建访问的 Domain 地址
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user