Send deletion thread and updated users revision

This commit is contained in:
Daniel García
2021-03-22 19:57:35 +01:00
parent 46a1a013cd
commit 1fc6c30652
6 changed files with 34 additions and 5 deletions

View File

@ -5,6 +5,8 @@ mod organizations;
pub mod two_factor;
mod sends;
pub use sends::start_send_deletion_scheduler;
pub fn routes() -> Vec<Route> {
let mut mod_routes = routes![
clear_device_token,

View File

@ -25,6 +25,23 @@ pub fn routes() -> Vec<rocket::Route> {
]
}
pub fn start_send_deletion_scheduler(pool: crate::db::DbPool) {
std::thread::spawn(move || {
loop {
if let Ok(conn) = pool.get() {
info!("Initiating send deletion");
for send in Send::find_all(&conn) {
if chrono::Utc::now().naive_utc() >= send.deletion_date {
send.delete(&conn).ok();
}
}
}
std::thread::sleep(std::time::Duration::from_secs(3600));
}
});
}
#[derive(Deserialize)]
#[allow(non_snake_case)]
pub struct SendData {
@ -370,10 +387,6 @@ fn delete_send(id: String, headers: Headers, conn: DbConn, nt: Notify) -> EmptyR
err!("Send is not owned by user")
}
if send.atype == SendType::File as i32 {
std::fs::remove_dir_all(Path::new(&CONFIG.sends_folder()).join(&send.uuid)).ok();
}
send.delete(&conn)?;
nt.send_user_update(UpdateType::SyncSendDelete, &headers.user);