mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-19 23:32:58 -05:00
Added failure constructor for response
This commit is contained in:
parent
46eaf5b4fd
commit
d66d1145fd
1 changed files with 13 additions and 15 deletions
28
src/main.rs
28
src/main.rs
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue