Fix updating file send

This commit is contained in:
Daniel García 2021-03-17 19:39:48 +01:00
parent b987ba506d
commit 551810c486
No known key found for this signature in database
GPG Key ID: FC8A7D14C3CD543A
1 changed files with 12 additions and 16 deletions

View File

@ -323,27 +323,23 @@ fn put_send(id: String, data: JsonUpcase<SendData>, headers: Headers, conn: DbCo
err!("Sends can't change type") err!("Sends can't change type")
} }
let data_val = if data.Type == SendType::Text as i32 { // When updating a file Send, we receive nulls in the File field, as it's immutable,
data.Text // so we only need to update the data field in the Text case
} else if data.Type == SendType::File as i32 { if data.Type == SendType::Text as i32 {
data.File let data_str = if let Some(mut d) = data.Text {
} else {
err!("Invalid Send type")
};
let data_str = if let Some(mut d) = data_val {
d.as_object_mut().and_then(|d| d.remove("Response")); d.as_object_mut().and_then(|d| d.remove("Response"));
serde_json::to_string(&d)? serde_json::to_string(&d)?
} else { } else {
err!("Send data not provided"); err!("Send data not provided");
}; };
send.data = data_str;
}
if data.DeletionDate > Utc::now() + Duration::days(31) { if data.DeletionDate > Utc::now() + Duration::days(31) {
err!( err!(
"You cannot have a Send with a deletion date that far into the future. Adjust the Deletion Date to a value less than 31 days from now and try again." "You cannot have a Send with a deletion date that far into the future. Adjust the Deletion Date to a value less than 31 days from now and try again."
); );
} }
send.data = data_str;
send.name = data.Name; send.name = data.Name;
send.akey = data.Key; send.akey = data.Key;
send.deletion_date = data.DeletionDate.naive_utc(); send.deletion_date = data.DeletionDate.naive_utc();