mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-07 07:35:25 +00:00
Fix issue with avatar / icon deletion when saving settings.
- Fixes #4763
This commit is contained in:
parent
69b4c6647b
commit
5f340d979d
1 changed files with 7 additions and 5 deletions
|
@ -338,16 +338,18 @@ async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Lemm
|
|||
}
|
||||
}
|
||||
|
||||
/// When adding a new avatar or similar image, delete the old one.
|
||||
/// When adding a new avatar, banner or similar image, delete the old one.
|
||||
pub async fn replace_image(
|
||||
new_image: &Option<String>,
|
||||
old_image: &Option<DbUrl>,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> LemmyResult<()> {
|
||||
if new_image.is_some() {
|
||||
// Ignore errors because image may be stored externally.
|
||||
if let Some(avatar) = &old_image {
|
||||
let image = LocalImage::delete_by_url(&mut context.pool(), avatar)
|
||||
if let (Some(new_image), Some(old_image)) = (new_image, old_image) {
|
||||
// Note: Oftentimes front ends will include the current image in the form,
|
||||
// so only delete if the urls are different.
|
||||
if new_image != old_image.as_str() {
|
||||
// Ignore errors because image may be stored externally.
|
||||
let image = LocalImage::delete_by_url(&mut context.pool(), old_image)
|
||||
.await
|
||||
.ok();
|
||||
if let Some(image) = image {
|
||||
|
|
Loading…
Reference in a new issue