Added failure constructor for response

This commit is contained in:
G2-Games 2024-10-26 22:41:42 -05:00
parent 46eaf5b4fd
commit d66d1145fd

View file

@ -119,28 +119,16 @@ async fn handle_upload(
let expire_time = if let Ok(t) = parse_time_string(&file_data.expire_time) { let expire_time = if let Ok(t) = parse_time_string(&file_data.expire_time) {
if t > settings.duration.maximum { if t > settings.duration.maximum {
return Ok(Json(ClientResponse { return Ok(Json(ClientResponse::failure("Duration larger than maximum")))
status: false,
response: "Duration larger than maximum",
..Default::default()
}))
} }
if settings.duration.restrict_to_allowed && !settings.duration.allowed.contains(&t) { if settings.duration.restrict_to_allowed && !settings.duration.allowed.contains(&t) {
return Ok(Json(ClientResponse { return Ok(Json(ClientResponse::failure("Duration not allowed")))
status: false,
response: "Duration is disallowed",
..Default::default()
}))
} }
t t
} else { } else {
return Ok(Json(ClientResponse { return Ok(Json(ClientResponse::failure("Duration invalid")))
status: false,
response: "Invalid duration",
..Default::default()
}))
}; };
// TODO: Properly sanitize this... // TODO: Properly sanitize this...
@ -220,6 +208,16 @@ struct ClientResponse {
pub expires: Option<DateTime<Utc>>, pub expires: Option<DateTime<Utc>>,
} }
impl ClientResponse {
fn failure(response: &'static str) -> Self {
Self {
status: false,
response,
..Default::default()
}
}
}
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {
// Get or create config file // Get or create config file