fix: Qiniu 下载域名改回 QINIU_DOWNLOAD_DOMAIN 环境变量
This commit is contained in:
@@ -24,7 +24,7 @@ public class QiniuStorageService implements StorageService {
|
||||
private Client qiniuClient;
|
||||
private Auth auth;
|
||||
private String bucket;
|
||||
private String ioHost;
|
||||
private String downloadDomain;
|
||||
|
||||
private synchronized void ensureInit() {
|
||||
if (bucket != null) return;
|
||||
@@ -32,6 +32,7 @@ public class QiniuStorageService implements StorageService {
|
||||
String sk = env("QINIU_SK");
|
||||
String regionStr = env("QINIU_REGION", "z2");
|
||||
this.bucket = env("QINIU_BUCKET", "par-configs");
|
||||
this.downloadDomain = env("QINIU_DOWNLOAD_DOMAIN");
|
||||
this.auth = Auth.create(ak, sk);
|
||||
Region region = switch (regionStr) {
|
||||
case "z0" -> Region.region0();
|
||||
@@ -42,18 +43,10 @@ public class QiniuStorageService implements StorageService {
|
||||
default -> Region.autoRegion();
|
||||
};
|
||||
Configuration cfg = new Configuration(region);
|
||||
this.ioHost = switch (regionStr) {
|
||||
case "z0" -> "iovip-z0.qiniuio.com";
|
||||
case "z1" -> "iovip-z1.qiniuio.com";
|
||||
case "z2" -> "iovip-z2.qiniuio.com";
|
||||
case "na0" -> "iovip-na0.qiniuio.com";
|
||||
case "as0" -> "iovip-as0.qiniuio.com";
|
||||
default -> "iovip-z2.qiniuio.com";
|
||||
};
|
||||
this.uploadManager = new UploadManager(cfg);
|
||||
this.bucketManager = new BucketManager(auth, cfg);
|
||||
this.qiniuClient = new Client(cfg);
|
||||
log.info("Qiniu 存储就绪: bucket={}, ioHost={}", bucket, ioHost);
|
||||
log.info("Qiniu 存储就绪: bucket={}, downloadDomain={}", bucket, downloadDomain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,13 +64,17 @@ public class QiniuStorageService implements StorageService {
|
||||
@Override
|
||||
public String read(String path) {
|
||||
ensureInit();
|
||||
// 通过 SDK Client + 区域 ioHost 私密下载
|
||||
String baseUrl = "http://" + ioHost + "/" + path;
|
||||
// 通过 SDK Client + downloadDomain 私密下载
|
||||
if (downloadDomain == null) {
|
||||
log.warn("Qiniu 读取失败: QINIU_DOWNLOAD_DOMAIN 未配置");
|
||||
return null;
|
||||
}
|
||||
String baseUrl = downloadDomain + "/" + path;
|
||||
String signedUrl = auth.privateDownloadUrl(baseUrl, 3600);
|
||||
try {
|
||||
Response resp = qiniuClient.get(signedUrl);
|
||||
if (resp.isOK()) return resp.bodyString();
|
||||
log.warn("Qiniu 读取失败 {}: HTTP {}", path, resp.statusCode);
|
||||
log.warn("Qiniu 读取失败 {}: HTTP {} (domain={})", path, resp.statusCode, downloadDomain);
|
||||
} catch (QiniuException e) {
|
||||
log.warn("Qiniu 读取失败 {}: {}", path, e.response != null ? e.response.error : e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user