rustisms from thorn

main
Ashelyn Dawn 1 month ago committed by Ashelyn Rose
parent 7286b95edb
commit e0873fa451
No known key found for this signature in database
GPG Key ID: D1980B8C6F349BC1

@ -31,14 +31,12 @@ pub async fn handler(state: &rocket::State<crate::State>, client_ip: ClientIp, s
{
let rate_limit = &state.rate_limit;
if client_ip.0.is_none() {
return Err((Status::InternalServerError, Json(Response {
let client_ip = client_ip.0.ok_or(
(Status::InternalServerError, Json(Response {
status: "error",
message: Some("Could not identify client IP".to_string())
})))
}
let client_ip = client_ip.0.unwrap();
}))
)?;
let rate_limit_outcome = rate_limit.check_key(&client_ip);
@ -59,14 +57,12 @@ pub async fn handler(state: &rocket::State<crate::State>, client_ip: ClientIp, s
form.slug == slug
});
if form_conf.is_none() {
return Err((Status::NotFound, Json(Response {
let form_conf = form_conf.ok_or(
(Status::NotFound, Json(Response {
status: "notfound",
message: Some(format!("Form ID {} not found", slug))
})));
}
let form_conf = form_conf.unwrap();
}))
)?;
let mut message_text = format!(
"You have recieved a message on {}:

@ -19,11 +19,11 @@ pub struct State {
fn rocket() -> _ {
let args: Vec<String> = std::env::args().collect();
if args.len() - 1 != 1 {
let [_exe, path] = args.as_slice() else {
panic!("Expected 1 argument, got {}", args.len() - 1)
}
};
let path = Path::new(&args[1]);
let path = Path::new(path);
let config = crate::config::Config::parse(path).unwrap();
let smtp_builder = SmtpClientBuilder::new(config.mailer.host.clone(), config.mailer.port)
@ -38,7 +38,7 @@ fn rocket() -> _ {
Duration::from_secs(config.rate_limit.replenish_seconds.into())
).unwrap().allow_burst(config.rate_limit.burst_max);
let rate_limit : RateLimiter<IpAddr, _, _> = RateLimiter::dashmap(quota);
let rate_limit = RateLimiter::dashmap(quota);
let state = State {
config,
@ -49,7 +49,7 @@ fn rocket() -> _ {
let rocket_conf = rocket::config::Config {
limits: Limits::default()
.limit("json", 2.kibibytes()),
..rocket::config::Config::default()
..Default::default()
};
rocket::custom(rocket_conf)

Loading…
Cancel
Save