add config checks on backend
This commit is contained in:
parent
3bb83bb039
commit
5f65a171dd
|
@ -28,6 +28,12 @@ impl FormElement {
|
||||||
|
|
||||||
pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||||
|
|
||||||
|
if ! state.config.files.allow_uploads {
|
||||||
|
return Ok(
|
||||||
|
Box::new(warp::redirect(warp::http::Uri::from_static("/")))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let params: HashMap<String, FormElement> = form.and_then(|mut field| async move {
|
let params: HashMap<String, FormElement> = form.and_then(|mut field| async move {
|
||||||
let mut bytes: Vec<u8> = vec![];
|
let mut bytes: Vec<u8> = vec![];
|
||||||
while let Some(byte) = field.data().await {
|
while let Some(byte) = field.data().await {
|
||||||
|
@ -78,11 +84,15 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
|
||||||
let protected = params.get("passworded").unwrap_or(&check_off.clone()).as_str_or_reject()?;
|
let protected = params.get("passworded").unwrap_or(&check_off.clone()).as_str_or_reject()?;
|
||||||
let protected = protected == "on";
|
let protected = protected == "on";
|
||||||
let password: Option<String> = {
|
let password: Option<String> = {
|
||||||
let pass = params.get("password");
|
if ! state.config.files.allow_pass_protection {
|
||||||
if protected && pass.is_some() {
|
|
||||||
Some(pass.unwrap().as_str_or_reject()?)
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
|
} else {
|
||||||
|
let pass = params.get("password");
|
||||||
|
if protected && pass.is_some() {
|
||||||
|
Some(pass.unwrap().as_str_or_reject()?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,22 +125,22 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
|
||||||
}
|
}
|
||||||
|
|
||||||
if named.is_some() {
|
if named.is_some() {
|
||||||
is_named = named.unwrap().as_str_or_reject()? == "on";
|
if state.config.files.allow_custom_names {
|
||||||
|
is_named = false;
|
||||||
|
} else {
|
||||||
|
is_named = named.unwrap().as_str_or_reject()? == "on";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = File::create(
|
let file = File::create(
|
||||||
data.data.clone(),
|
data.data.clone(),
|
||||||
data.mime.clone(),
|
data.mime.clone(),
|
||||||
match named {
|
{
|
||||||
Some(named) => {
|
if is_named {
|
||||||
if named.as_str_or_reject()?
|
Some(filename.as_str_or_reject()?)
|
||||||
.to_string() == "on" {
|
} else {
|
||||||
Some(filename.as_str_or_reject()?)
|
None
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => None
|
|
||||||
},
|
},
|
||||||
state.env.clone(),
|
state.env.clone(),
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue