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