From 72abd4d5bd2ca8ddce0b33779f93950e1350796b Mon Sep 17 00:00:00 2001 From: blek Date: Fri, 3 Nov 2023 00:08:45 +1000 Subject: [PATCH] add a ToS switch --- filed/src/web/curlapi/upload.rs | 16 ++++++++++++++++ filed/src/web/forms.rs | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/filed/src/web/curlapi/upload.rs b/filed/src/web/curlapi/upload.rs index fa85a1f..8658cf5 100644 --- a/filed/src/web/curlapi/upload.rs +++ b/filed/src/web/curlapi/upload.rs @@ -24,6 +24,22 @@ pub async fn upload(form: FormData, ip: Option, state: SharedState) -> R .await .map_err(|x| HttpReject::WarpError(x))?; + if let Some(consent) = params.get("tos_consent") { + if consent.data != "on".bytes().collect::>() { + return Ok( + Box::new( + format!("You need to agree to the ToS to upload a file.\nSee {}/curlapi/help for details\n\nTo agree to the ToS, add a -F'tos_consent=on'\n", state.env.instanceurl) + ) + ) + } + } else { + return Ok( + Box::new( + format!("You need to agree to the ToS to upload a file.\nSee {}/curlapi/help for details\n\nTo agree to the ToS, add a -F'tos_consent=on'\n", state.env.instanceurl) + ) + ) + } + let formdata = UploadFormData::from_formdata(params, true); if let Some(formdata) = formdata { diff --git a/filed/src/web/forms.rs b/filed/src/web/forms.rs index a8adc81..cbfcecf 100644 --- a/filed/src/web/forms.rs +++ b/filed/src/web/forms.rs @@ -18,8 +18,8 @@ use super::{state::SharedState, pages::{UploadSuccessPage, ErrorPage}, rejection #[derive(Debug, Serialize, Clone)] pub struct FormElement { - data: Vec, - mime: String + pub data: Vec, + pub mime: String } impl FormElement {