Delete old avatar; fix database migration.
This commit is contained in:
@@ -86,4 +86,25 @@ impl File {
|
|||||||
Err(Error::UnknownAttachment)
|
Err(Error::UnknownAttachment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete(&self) -> Result<()> {
|
||||||
|
get_collection("attachments")
|
||||||
|
.update_one(
|
||||||
|
doc! {
|
||||||
|
"_id": &self.id
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"deleted": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "update_one",
|
||||||
|
with: "attachment",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,23 +236,7 @@ impl Message {
|
|||||||
|
|
||||||
pub async fn delete(&self) -> Result<()> {
|
pub async fn delete(&self) -> Result<()> {
|
||||||
if let Some(attachment) = &self.attachment {
|
if let Some(attachment) = &self.attachment {
|
||||||
get_collection("attachments")
|
attachment.delete().await?;
|
||||||
.update_one(
|
|
||||||
doc! {
|
|
||||||
"_id": &attachment.id
|
|
||||||
},
|
|
||||||
doc! {
|
|
||||||
"$set": {
|
|
||||||
"deleted": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|_| Error::DatabaseError {
|
|
||||||
operation: "update_one",
|
|
||||||
with: "attachment",
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_collection("messages")
|
get_collection("messages")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 1;
|
pub const LATEST_REVISION: i32 = 2;
|
||||||
|
|
||||||
pub async fn migrate_database() {
|
pub async fn migrate_database() {
|
||||||
let migrations = get_collection("migrations");
|
let migrations = get_collection("migrations");
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ pub async fn req(user: User, mut data: Json<Data>, _ignore_id: String) -> Result
|
|||||||
.publish(user.id.clone())
|
.publish(user.id.clone())
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
if let Some(old_avatar) = user.avatar {
|
||||||
|
old_avatar.delete().await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user