fix: 私有空间直接用认证源站下载,不走 CDN

This commit is contained in:
mediabot-pt
2026-06-30 16:59:09 +08:00
parent 5fc2bf764a
commit 682b19cb35

View File

@@ -70,27 +70,17 @@ public class QiniuStorageService implements StorageService {
@Override
public String read(String path) {
ensureInit();
// 先走 CDN,404 则回退源站直读
String content = readFromUrl(cdnDomain + "/" + path, path);
if (content != null) return content;
// CDN 缓存未命中,走 Qiniu 源站
// 私有空间走认证源站下载
String sourceUrl = "https://" + bucket + ".qiniucdn.com/" + path;
String privateUrl = auth.privateDownloadUrl(sourceUrl, 3600);
content = readFromUrl(privateUrl, path);
if (content != null) return content;
log.warn("Qiniu 读取失败 {}: CDN+源站均不可用", path);
return null;
}
private String readFromUrl(String url, String path) {
String signedUrl = auth.privateDownloadUrl(sourceUrl, 3600);
try {
var req = HttpRequest.newBuilder().uri(URI.create(url))
var req = HttpRequest.newBuilder().uri(URI.create(signedUrl))
.timeout(Duration.ofSeconds(10)).GET().build();
var resp = httpClient.send(req, HttpResponse.BodyHandlers.ofString());
if (resp.statusCode() == 200) return resp.body();
log.debug("Qiniu CDN miss {}: HTTP {}", path, resp.statusCode());
log.warn("Qiniu 读取失败 {}: HTTP {}", path, resp.statusCode());
} catch (Exception e) {
log.debug("Qiniu 读取异常 {}: {}", path, e.getMessage());
log.warn("Qiniu 读取失败 {}: {}", path, e.getMessage());
}
return null;
}