mirror of
https://github.com/zfile-dev/zfile.git
synced 2025-04-19 05:34:52 +00:00
🐛 修复七牛对私有空间使用自定义域名后无法正常下载的 bug
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package im.zhaojun.zfile.module.storage.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
||||
import com.amazonaws.auth.BasicAWSCredentials;
|
||||
import com.amazonaws.client.builder.AwsClientBuilder;
|
||||
@@ -29,6 +31,8 @@ public class QiniuServiceImpl extends AbstractS3BaseFileService<QiniuParam> {
|
||||
|
||||
private BucketManager bucketManager;
|
||||
|
||||
private Auth auth;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
BasicAWSCredentials credentials = new BasicAWSCredentials(param.getAccessKey(), param.getSecretKey());
|
||||
@@ -37,7 +41,7 @@ public class QiniuServiceImpl extends AbstractS3BaseFileService<QiniuParam> {
|
||||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(param.getEndPoint(), "kodo")).build();
|
||||
|
||||
Configuration cfg = new Configuration(Region.autoRegion());
|
||||
Auth auth = Auth.create(param.getAccessKey(), param.getSecretKey());
|
||||
auth = Auth.create(param.getAccessKey(), param.getSecretKey());
|
||||
bucketManager = new BucketManager(auth, cfg);
|
||||
|
||||
setUploadCors();
|
||||
@@ -65,7 +69,26 @@ public class QiniuServiceImpl extends AbstractS3BaseFileService<QiniuParam> {
|
||||
} catch (QiniuException e) {
|
||||
throw ExceptionUtil.wrapRuntime(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDownloadUrl(String pathAndName) {
|
||||
String domain = param.getDomain();
|
||||
|
||||
Integer tokenTime = param.getTokenTime();
|
||||
if (param.getTokenTime() == null || param.getTokenTime() < 1) {
|
||||
tokenTime = 1800;
|
||||
}
|
||||
|
||||
String fullPath = StringUtils.concatTrimStartSlashes(param.getBasePath() + pathAndName);
|
||||
// 如果不是私有空间, 且指定了加速域名, 则使用 qiniu 的 sdk 获取下载链接
|
||||
// (使用 s3 sdk 获取到的下载链接替换自动加速域名后无法访问, 故这里使用 qiniu sdk).
|
||||
if (BooleanUtil.isTrue(param.isPrivate()) && StrUtil.isNotEmpty(domain)) {
|
||||
String customDomainFullPath = StringUtils.removeDuplicateSlashes(domain + "/" + StringUtils.encodeAllIgnoreSlashes(fullPath));
|
||||
return auth.privateDownloadUrl(customDomainFullPath, tokenTime);
|
||||
}
|
||||
|
||||
return super.getDownloadUrl(pathAndName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user