mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
allow deleting dangling thumbnails
Previously attempting to delete an MXC that is only associated with dangling thumbnails would fail, because it assumes that every thumbnail must have a corresponding original in the db, and errors out if it can't find the original. This is incorrect because we create dangling thumbnails when requesting a remote thumbnail over federation when we don't have the original file.
This commit is contained in:
parent
916088a22f
commit
46e8a63489
1 changed files with 21 additions and 12 deletions
|
|
@ -117,16 +117,11 @@ impl Service {
|
||||||
/// Deletes a media object and all associated thumbnails.
|
/// Deletes a media object and all associated thumbnails.
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub(crate) async fn delete(&self, mxc: OwnedMxcUri) -> Result<()> {
|
pub(crate) async fn delete(&self, mxc: OwnedMxcUri) -> Result<()> {
|
||||||
let (_, key) = self
|
let mut any_files = false;
|
||||||
.db
|
|
||||||
.search_file_metadata(mxc.clone(), 0, 0)
|
|
||||||
.inspect_err(
|
|
||||||
|error| warn!(%error, "Failed to find original media key"),
|
|
||||||
)?
|
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Media not found"))?;
|
|
||||||
|
|
||||||
let thumbnails = self.db.search_thumbnails_metadata(mxc)?;
|
let thumbnails = self.db.search_thumbnails_metadata(mxc.clone())?;
|
||||||
for (_, thumbnail_key) in thumbnails {
|
for (_, thumbnail_key) in thumbnails {
|
||||||
|
any_files = true;
|
||||||
self.delete_by_key(thumbnail_key.clone()).await.inspect_err(
|
self.delete_by_key(thumbnail_key.clone()).await.inspect_err(
|
||||||
|error| {
|
|error| {
|
||||||
warn!(
|
warn!(
|
||||||
|
|
@ -140,11 +135,25 @@ impl Service {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.delete_by_key(key).await.inspect_err(
|
if let Some((_, key)) =
|
||||||
|error| warn!(%error, "Failed to delete original media"),
|
self.db.search_file_metadata(mxc, 0, 0).inspect_err(
|
||||||
)?;
|
|error| warn!(%error, "Failed to find original media key"),
|
||||||
|
)?
|
||||||
|
{
|
||||||
|
any_files = true;
|
||||||
|
self.delete_by_key(key).await.inspect_err(
|
||||||
|
|error| warn!(%error, "Failed to delete original media"),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
if any_files {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
let error =
|
||||||
|
Error::BadRequest(ErrorKind::NotFound, "Media not found");
|
||||||
|
warn!(%error, "Failed to delete media");
|
||||||
|
Err(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes a specific media key, which may or may not be a thumbnail.
|
/// Deletes a specific media key, which may or may not be a thumbnail.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue