提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.framework.file.core.client.s3; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import com.iailab.module.infra.framework.file.core.client.FileClientConfig; |
|
5 |
import com.fasterxml.jackson.annotation.JsonIgnore; |
|
6 |
import lombok.Data; |
|
7 |
import org.hibernate.validator.constraints.URL; |
|
8 |
|
|
9 |
import javax.validation.constraints.AssertTrue; |
|
10 |
import javax.validation.constraints.NotNull; |
|
11 |
|
|
12 |
/** |
|
13 |
* S3 文件客户端的配置类 |
|
14 |
* |
|
15 |
* @author iailab |
|
16 |
*/ |
|
17 |
@Data |
|
18 |
public class S3FileClientConfig implements FileClientConfig { |
|
19 |
|
|
20 |
public static final String ENDPOINT_QINIU = "qiniucs.com"; |
|
21 |
public static final String ENDPOINT_ALIYUN = "aliyuncs.com"; |
|
22 |
public static final String ENDPOINT_TENCENT = "myqcloud.com"; |
4a47e4
|
23 |
public static final String ENDPOINT_VOLCES = "volces.com"; // 火山云(字节) |
e7c126
|
24 |
|
H |
25 |
/** |
|
26 |
* 节点地址 |
|
27 |
* 1. MinIO:https://www.baidu.com/Spring-Boot/MinIO 。例如说,http://127.0.0.1:9000 |
|
28 |
* 2. 阿里云:https://help.aliyun.com/document_detail/31837.html |
|
29 |
* 3. 腾讯云:https://cloud.tencent.com/document/product/436/6224 |
|
30 |
* 4. 七牛云:https://developer.qiniu.com/kodo/4088/s3-access-domainname |
|
31 |
* 5. 华为云:https://developer.huaweicloud.com/endpoint?OBS |
|
32 |
*/ |
|
33 |
@NotNull(message = "endpoint 不能为空") |
|
34 |
private String endpoint; |
|
35 |
/** |
|
36 |
* 自定义域名 |
|
37 |
* 1. MinIO:通过 Nginx 配置 |
|
38 |
* 2. 阿里云:https://help.aliyun.com/document_detail/31836.html |
|
39 |
* 3. 腾讯云:https://cloud.tencent.com/document/product/436/11142 |
|
40 |
* 4. 七牛云:https://developer.qiniu.com/kodo/8556/set-the-custom-source-domain-name |
|
41 |
* 5. 华为云:https://support.huaweicloud.com/usermanual-obs/obs_03_0032.html |
|
42 |
*/ |
|
43 |
@URL(message = "domain 必须是 URL 格式") |
|
44 |
private String domain; |
|
45 |
/** |
|
46 |
* 存储 Bucket |
|
47 |
*/ |
|
48 |
@NotNull(message = "bucket 不能为空") |
|
49 |
private String bucket; |
|
50 |
|
|
51 |
/** |
|
52 |
* 访问 Key |
|
53 |
* 1. MinIO:https://www.baidu.com/Spring-Boot/MinIO |
|
54 |
* 2. 阿里云:https://ram.console.aliyun.com/manage/ak |
|
55 |
* 3. 腾讯云:https://console.cloud.tencent.com/cam/capi |
|
56 |
* 4. 七牛云:https://portal.qiniu.com/user/key |
|
57 |
* 5. 华为云:https://support.huaweicloud.com/qs-obs/obs_qs_0005.html |
|
58 |
*/ |
|
59 |
@NotNull(message = "accessKey 不能为空") |
|
60 |
private String accessKey; |
|
61 |
/** |
|
62 |
* 访问 Secret |
|
63 |
*/ |
|
64 |
@NotNull(message = "accessSecret 不能为空") |
|
65 |
private String accessSecret; |
|
66 |
|
|
67 |
@SuppressWarnings("RedundantIfStatement") |
|
68 |
@AssertTrue(message = "domain 不能为空") |
|
69 |
@JsonIgnore |
|
70 |
public boolean isDomainValid() { |
|
71 |
// 如果是七牛,必须带有 domain |
|
72 |
if (StrUtil.contains(endpoint, ENDPOINT_QINIU) && StrUtil.isEmpty(domain)) { |
|
73 |
return false; |
|
74 |
} |
|
75 |
return true; |
|
76 |
} |
|
77 |
|
|
78 |
} |