fix: Qiniu下载先试公开URL不用签名,缓存层CachedStorageService已在用

This commit is contained in:
mediabot-pt
2026-07-01 18:14:13 +08:00
parent 5ae76bc69d
commit a4a11fb503

View File

@@ -87,15 +87,20 @@ public class QiniuStorageService implements StorageService {
log.warn("Qiniu stat 失败 {}: {}", path, e.response != null ? e.response.error : e.getMessage());
}
// 手动拼接 URL + privateDownloadUrl 签名
String baseUrl = "http://" + downloadDomain + "/" + path;
String signedUrl = auth.privateDownloadUrl(baseUrl, 3600);
// 直接 HTTP 拉取(公开桶),不用签名
String rawUrl = "http://" + downloadDomain + "/" + path;
try {
var req = HttpRequest.newBuilder().uri(URI.create(signedUrl))
var req = HttpRequest.newBuilder().uri(URI.create(rawUrl))
.timeout(Duration.ofSeconds(10)).GET().build();
var resp = httpClient.send(req, HttpResponse.BodyHandlers.ofString());
if (resp.statusCode() == 200) return resp.body();
log.warn("Qiniu 下载失败 {}: HTTP {} url={}", path, resp.statusCode(), signedUrl);
// 公开桶失败,尝试签名URL
String signedUrl = auth.privateDownloadUrl(rawUrl, 3600);
req = HttpRequest.newBuilder().uri(URI.create(signedUrl))
.timeout(Duration.ofSeconds(10)).GET().build();
resp = httpClient.send(req, HttpResponse.BodyHandlers.ofString());
if (resp.statusCode() == 200) return resp.body();
log.warn("Qiniu 下载失败 {}: HTTP {}", path, resp.statusCode());
} catch (Exception e) {
log.warn("Qiniu 下载失败 {}: {}", path, e.getMessage());
}