WIP
This commit is contained in:
parent
fe646f4372
commit
9d1dbfb2f5
2 changed files with 60 additions and 1 deletions
|
@ -175,7 +175,7 @@ struct Meta {
|
||||||
object_storage_region: Option<String>,
|
object_storage_region: Option<String>,
|
||||||
object_storage_access_key: Option<String>,
|
object_storage_access_key: Option<String>,
|
||||||
object_storage_secret_key: Option<String>,
|
object_storage_secret_key: Option<String>,
|
||||||
object_storage_port: Option<i32>,
|
// object_storage_port: Option<i32>,
|
||||||
object_storage_use_ssl: bool,
|
object_storage_use_ssl: bool,
|
||||||
object_storage_set_public_read: bool,
|
object_storage_set_public_read: bool,
|
||||||
object_storage_s3_force_path_style: bool,
|
object_storage_s3_force_path_style: bool,
|
||||||
|
@ -352,11 +352,51 @@ fn create_new_server_config(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let object_storage = match meta.use_object_storage {
|
||||||
|
false => None,
|
||||||
|
true => Some(server::ObjectStorage {
|
||||||
|
enabled: true,
|
||||||
|
base_url: meta
|
||||||
|
.object_storage_base_url
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("Object storage base url is not set"))?,
|
||||||
|
bucket: meta
|
||||||
|
.object_storage_bucket
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig(
|
||||||
|
"Object storage bucket name is not set",
|
||||||
|
))?,
|
||||||
|
prefix: meta
|
||||||
|
.object_storage_prefix
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("Object storage prefix is not set"))?,
|
||||||
|
endpoint: {
|
||||||
|
if meta.object_storage_endpoint.is_none() {
|
||||||
|
cprintln!("<y!>Warning:</> Since the object storage endpoint is not set, we assume that you are using AWS S3. If it's not the case, please fill in the `file.object_storage.endpoint` field in `config/server.toml`.");
|
||||||
|
}
|
||||||
|
meta.object_storage_endpoint.to_owned()
|
||||||
|
},
|
||||||
|
region: meta.object_storage_region.to_owned(),
|
||||||
|
access_key: meta
|
||||||
|
.object_storage_access_key
|
||||||
|
.to_owned()
|
||||||
|
.ok_or(Error::InvalidConfig("Object storage access key is not set"))?,
|
||||||
|
access_secret: meta.object_storage_secret_key.to_owned().ok_or(
|
||||||
|
Error::InvalidConfig("Object storage access secret is not set"),
|
||||||
|
)?,
|
||||||
|
use_ssl: meta.object_storage_use_ssl,
|
||||||
|
use_proxy: meta.object_storage_use_proxy,
|
||||||
|
set_public_read: meta.object_storage_set_public_read,
|
||||||
|
use_path_based_url: meta.object_storage_s3_force_path_style,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
let file = {
|
let file = {
|
||||||
let mut file = server::File {
|
let mut file = server::File {
|
||||||
max_size: None,
|
max_size: None,
|
||||||
proxy_remote_file: None,
|
proxy_remote_file: None,
|
||||||
cache_remote_file: None,
|
cache_remote_file: None,
|
||||||
|
object_storage,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(max_size) = default_yml.get("maxFileSize") {
|
if let Some(max_size) = default_yml.get("maxFileSize") {
|
||||||
|
@ -381,6 +421,7 @@ fn create_new_server_config(
|
||||||
if file.max_size.is_none()
|
if file.max_size.is_none()
|
||||||
&& file.proxy_remote_file.is_none()
|
&& file.proxy_remote_file.is_none()
|
||||||
&& file.proxy_remote_file.is_none()
|
&& file.proxy_remote_file.is_none()
|
||||||
|
&& file.object_storage.is_none()
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -157,6 +157,24 @@ pub struct File {
|
||||||
pub max_size: Option<u64>,
|
pub max_size: Option<u64>,
|
||||||
pub proxy_remote_file: Option<bool>,
|
pub proxy_remote_file: Option<bool>,
|
||||||
pub cache_remote_file: Option<bool>,
|
pub cache_remote_file: Option<bool>,
|
||||||
|
pub object_storage: Option<ObjectStorage>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Validate, Debug, Clone)]
|
||||||
|
pub struct ObjectStorage {
|
||||||
|
pub enabled: bool,
|
||||||
|
#[validate(url)]
|
||||||
|
pub base_url: String,
|
||||||
|
pub bucket: String,
|
||||||
|
pub prefix: String,
|
||||||
|
pub endpoint: Option<String>,
|
||||||
|
pub region: Option<String>,
|
||||||
|
pub access_key: String,
|
||||||
|
pub access_secret: String,
|
||||||
|
pub use_ssl: bool,
|
||||||
|
pub use_proxy: bool,
|
||||||
|
pub set_public_read: bool,
|
||||||
|
pub use_path_based_url: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Validate, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Validate, Debug, Clone)]
|
||||||
|
|
Loading…
Reference in a new issue