Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Images uploaded and linked in post bodies are not purged but the references to them are lost #3504

Open
4 tasks done
Djones4822 opened this issue Jul 6, 2023 · 1 comment
Labels
area: media bug Something isn't working

Comments

@Djones4822
Copy link
Contributor

Requirements

  • Is this a bug report? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • Did you check to see if this issue already exists?
  • Is this only a single bug? Do not put multiple bugs in one issue.
  • Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.

Summary

In purge post an image is only purged from pictrs when the image url is included as the post url. In cases where the image is not the url, or where the body contains multiple images that were uploaded (commonly known as an "image set"), these are not removed.

However, because the references to these images is lost when the post body is deleted, it becomes impossible to retrieve them as we no longer know the alias that was used.

Steps to Reproduce

  1. Upload an image while making a post
  2. Do not include the image as the post url (or upload more than 1 image)
  3. Once posted, copy the image url that we are testing (any not included as the post url)
  4. Use an admin account to purge
  5. See that the link to the image is still valid

Technical Details

In my opinion, the offending code begins here: https://github.com/LemmyNet/lemmy/blob/main/crates/api/src/site/purge/post.rs#L36

    // Purge image
    if let Some(url) = post.url {
      purge_image_from_pictrs(context.client(), context.settings(), &url)
        .await
        .ok();
    }
    // Purge thumbnail
    if let Some(thumbnail_url) = post.thumbnail_url {
      purge_image_from_pictrs(context.client(), context.settings(), &thumbnail_url)
        .await
        .ok();
    }

The image purge needs to iterate over the url in the title AND the post body, searching for all references to pictrs on the domain.

The biggest problem is that the post body is deleted, so we don't even know where those images are and have no way to get them out of pictrs without opening each one.

Version

18.0

Lemmy Instance URL

No response

@Djones4822 Djones4822 added the bug Something isn't working label Jul 6, 2023
@Djones4822
Copy link
Contributor Author

Honestly I see this as an issue in all of the purge logic. For comments, there is no image check. In community and person purging, we're only purging the images that are in post urls, but not post body or comment bodies. But once the bodies containing the links are gone, the files are just lost in the sled db

I also don't seem to have a good way to inspect the sled db, if I could extract all the aliases I could query the db to find "orphaned" images like this mentions #1331

I see the convo here: #1809 (comment) - at least you guys saw it coming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: media bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants