use of com.jeesuite.cos.BucketConfig in project jeesuite-libs by vakinge.
the class AbstractProvider method getBucketUrlPrefix.
/**
* @param bucketName
* @return
*/
protected String getBucketUrlPrefix(String bucketName) {
BucketConfig config = currentBucketConfig(bucketName);
if (StringUtils.isNotBlank(config.getUrlPrefix())) {
return config.getUrlPrefix();
}
synchronized (bucketMappings) {
if (StringUtils.isNotBlank(config.getUrlPrefix())) {
return config.getUrlPrefix();
}
String urlPrefix = buildBucketUrlPrefix(bucketName);
config.setUrlPrefix(urlPrefix);
return urlPrefix;
}
}
use of com.jeesuite.cos.BucketConfig in project jeesuite-libs by vakinge.
the class MinioProvider method getBucketConfig.
@Override
public BucketConfig getBucketConfig(String bucketName) {
if (!existsBucket(bucketName)) {
return null;
}
boolean isPrivate = false;
try {
String bucketPolicy = minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket(bucketName).build());
isPrivate = StringUtils.isEmpty(bucketPolicy) ? true : false;
} catch (Exception e) {
throw new RuntimeException(e);
}
BucketConfig config = new BucketConfig(bucketName, isPrivate, null);
return config;
}
use of com.jeesuite.cos.BucketConfig in project jeesuite-libs by vakinge.
the class QcloudProvider method getBucketConfig.
@Override
public BucketConfig getBucketConfig(String bucketName) {
bucketName = buildBucketName(bucketName);
if (!cosclient.doesBucketExist(bucketName))
return null;
CannedAccessControlList acl = cosclient.getBucketAcl(bucketName).getCannedAccessControl();
return new BucketConfig(bucketName, acl == CannedAccessControlList.Private, null);
}
use of com.jeesuite.cos.BucketConfig in project jeesuite-libs by vakinge.
the class AbstractProvider method getDownloadUrl.
@Override
public String getDownloadUrl(String bucketName, String fileKey, int expireInSeconds) {
BucketConfig config = currentBucketConfig(bucketName);
String url;
if (config.isAuth()) {
fileKey = resolveFileKey(bucketName, fileKey);
String presignedUrl = generatePresignedUrl(bucketName, fileKey, expireInSeconds);
String urlprefix = getBucketUrlPrefix(bucketName);
url = presignedUrl.replaceFirst(URL_PREFIX_PATTERN, urlprefix);
} else {
url = getFullPath(bucketName, fileKey);
}
return url;
}
use of com.jeesuite.cos.BucketConfig in project jeesuite-libs by vakinge.
the class AliyunProvider method createUploadToken.
@Override
public Map<String, Object> createUploadToken(UploadTokenParam param) {
BucketConfig config = currentBucketConfig(param.getBucketName());
Map<String, Object> result = new HashMap<>();
PolicyConditions policyConds = new PolicyConditions();
if (param.getFsizeMin() != null && param.getFsizeMax() != null) {
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, param.getFsizeMin(), param.getFsizeMax());
} else {
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
}
if (param.getUploadDir() != null) {
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, param.getUploadDir());
}
if (StringUtils.isBlank(param.getCallbackHost())) {
param.setCallbackHost(StringUtils.remove(config.getUrlPrefix(), "/").split(":")[1]);
}
if (StringUtils.isBlank(param.getCallbackBody())) {
param.setCallbackBody(DEFAULT_CALLBACK_BODY);
}
Date expire = DateUtils.addSeconds(new Date(), (int) param.getExpires());
String policy = ossClient.generatePostPolicy(expire, policyConds);
String policyBase64 = null;
String callbackBase64 = null;
try {
policyBase64 = BinaryUtil.toBase64String(policy.getBytes(StandardCharsets.UTF_8.name()));
String callbackJson = param.getCallbackRuleAsJson();
if (callbackJson != null) {
callbackBase64 = BinaryUtil.toBase64String(callbackJson.getBytes(StandardCharsets.UTF_8.name()));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
String signature = ossClient.calculatePostSignature(policy);
result.put("OSSAccessKeyId", conf.getAccessKey());
result.put("policy", policyBase64);
result.put("signature", signature);
result.put("host", config.getUrlPrefix());
result.put("dir", param.getUploadDir());
result.put("expire", String.valueOf(expire.getTime()));
if (callbackBase64 != null) {
result.put("callback", callbackBase64);
}
return result;
}
Aggregations