add config checks on backend

This commit is contained in:
blek 2023-10-21 16:09:36 +10:00
parent 3bb83bb039
commit 5f65a171dd
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 25 additions and 15 deletions

View File

@ -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(),
{ {