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,12 +84,16 @@ 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> = {
if ! state.config.files.allow_pass_protection {
None
} else {
let pass = params.get("password"); let pass = params.get("password");
if protected && pass.is_some() { if protected && pass.is_some() {
Some(pass.unwrap().as_str_or_reject()?) Some(pass.unwrap().as_str_or_reject()?)
} else { } else {
None None
} }
}
}; };
let mut is_named = named.is_none(); let mut is_named = named.is_none();
@ -115,23 +125,23 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
} }
if named.is_some() { if named.is_some() {
if state.config.files.allow_custom_names {
is_named = false;
} else {
is_named = named.unwrap().as_str_or_reject()? == "on"; 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()?
.to_string() == "on" {
Some(filename.as_str_or_reject()?) Some(filename.as_str_or_reject()?)
} else { } else {
None None
} }
}, },
None => None
},
state.env.clone(), state.env.clone(),
{ {
if delmode == "30" { if delmode == "30" {