1use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, Serialize, Deserialize, Default)]
38pub struct CosConfig {
39 pub provider: String,
41 #[serde(default)]
43 pub tencent: TencentCosConfig,
44 #[serde(default)]
46 pub aliyun: AliyunOssConfig,
47 #[serde(default)]
49 pub aws: AwsS3Config,
50 #[serde(default)]
52 pub minio: MinioConfig,
53 #[serde(default)]
55 pub huawei: HuaweiObsConfig,
56 #[serde(default)]
58 pub rustfs: RustFsConfig,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
63pub struct TencentCosConfig {
64 pub secret_id: String,
66 pub secret_key: String,
68 pub bucket: String,
70 pub region: String,
72 pub cdn_domain: Option<String>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default)]
78pub struct AliyunOssConfig {
79 pub access_key_id: String,
81 pub access_key_secret: String,
83 pub bucket: String,
85 pub endpoint: String,
87 pub cdn_domain: Option<String>,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default)]
93pub struct AwsS3Config {
94 pub access_key_id: String,
96 pub secret_access_key: String,
98 pub bucket: String,
100 pub region: String,
102 pub endpoint: Option<String>,
104 pub cdn_domain: Option<String>,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, Default)]
110pub struct MinioConfig {
111 pub access_key: String,
113 pub secret_key: String,
115 pub bucket: String,
117 pub endpoint: String,
119 pub use_ssl: bool,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize, Default)]
125pub struct HuaweiObsConfig {
126 pub access_key_id: String,
128 pub secret_access_key: String,
130 pub bucket: String,
132 pub endpoint: String,
134 pub cdn_domain: Option<String>,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140pub struct RustFsConfig {
141 pub root_path: String,
143 pub public_url_prefix: String,
145 pub auto_create_dir: bool,
147}
148
149impl Default for RustFsConfig {
150 fn default() -> Self {
151 Self {
152 root_path: "./uploads".to_string(),
153 public_url_prefix: "/uploads".to_string(),
154 auto_create_dir: true,
155 }
156 }
157}
158
159impl CosConfig {
160 pub fn get_bucket(&self) -> String {
162 match self.provider.as_str() {
163 "tencent" => self.tencent.bucket.clone(),
164 "aliyun" => self.aliyun.bucket.clone(),
165 "aws" => self.aws.bucket.clone(),
166 "minio" => self.minio.bucket.clone(),
167 "huawei" => self.huawei.bucket.clone(),
168 "rustfs" => String::new(),
169 _ => String::new(),
170 }
171 }
172
173 pub fn get_cdn_domain(&self) -> Option<String> {
175 match self.provider.as_str() {
176 "tencent" => self.tencent.cdn_domain.clone(),
177 "aliyun" => self.aliyun.cdn_domain.clone(),
178 "aws" => self.aws.cdn_domain.clone(),
179 "huawei" => self.huawei.cdn_domain.clone(),
180 _ => None,
181 }
182 }
183
184 pub fn get_endpoint(&self) -> Option<String> {
186 match self.provider.as_str() {
187 "minio" => Some(self.minio.endpoint.clone()),
188 "huawei" => Some(self.huawei.endpoint.clone()),
189 "aliyun" => Some(self.aliyun.endpoint.clone()),
190 "aws" => self.aws.endpoint.clone(),
191 _ => None,
192 }
193 }
194
195 pub fn get_root_path(&self) -> Option<String> {
197 match self.provider.as_str() {
198 "rustfs" => Some(self.rustfs.root_path.clone()),
199 _ => None,
200 }
201 }
202}