fix: Qiniu 下载域名改为 QINIU_DOWNLOAD_DOMAIN 环境变量配置
This commit is contained in:
@@ -32,7 +32,7 @@ public class QiniuStorageService implements StorageService {
|
||||
private BucketManager bucketManager;
|
||||
private Auth auth;
|
||||
private String bucket;
|
||||
private String cdnDomain;
|
||||
private String downloadDomain;
|
||||
|
||||
private synchronized void ensureInit() {
|
||||
if (bucket != null) return;
|
||||
@@ -40,7 +40,7 @@ public class QiniuStorageService implements StorageService {
|
||||
String sk = env("QINIU_SK");
|
||||
String region = env("QINIU_REGION", "z2");
|
||||
this.bucket = env("QINIU_BUCKET", "par-configs");
|
||||
this.cdnDomain = env("QINIU_DOMAIN", "http://" + bucket + ".qiniucdn.com");
|
||||
this.downloadDomain = env("QINIU_DOWNLOAD_DOMAIN", "http://" + bucket + ".qiniudn.com");
|
||||
this.auth = Auth.create(ak, sk);
|
||||
Configuration cfg = new Configuration(switch (region) {
|
||||
case "z0" -> Region.region0();
|
||||
@@ -52,7 +52,7 @@ public class QiniuStorageService implements StorageService {
|
||||
});
|
||||
this.uploadManager = new UploadManager(cfg);
|
||||
this.bucketManager = new BucketManager(auth, cfg);
|
||||
log.info("Qiniu 存储就绪: bucket={}, domain={}", bucket, cdnDomain);
|
||||
log.info("Qiniu 存储就绪: bucket={}", bucket);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,15 +70,15 @@ public class QiniuStorageService implements StorageService {
|
||||
@Override
|
||||
public String read(String path) {
|
||||
ensureInit();
|
||||
// 私有空间走认证源站下载
|
||||
String sourceUrl = "http://" + bucket + ".qiniudn.com/" + path;
|
||||
String signedUrl = auth.privateDownloadUrl(sourceUrl, 3600);
|
||||
// 使用配置的下载域名生成私密下载链接
|
||||
String baseUrl = downloadDomain.endsWith("/") ? downloadDomain + path : downloadDomain + "/" + path;
|
||||
String signedUrl = auth.privateDownloadUrl(baseUrl, 3600);
|
||||
try {
|
||||
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.warn("Qiniu 读取失败 {}: HTTP {}", path, resp.statusCode());
|
||||
log.warn("Qiniu 读取失败 {}: HTTP {} (domain={})", path, resp.statusCode(), downloadDomain);
|
||||
} catch (Exception e) {
|
||||
log.warn("Qiniu 读取失败 {}: {}", path, e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user