mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-24 02:21:04 +00:00
Clean up file before saving
This commit is contained in:
parent
40264e372d
commit
d74df047c5
1 changed files with 5 additions and 0 deletions
|
@ -11,6 +11,7 @@ from PIL import Image, ImageDraw, ImageFont, ImageOps, ImageColor
|
|||
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.files.uploadedfile import InMemoryUploadedFile
|
||||
from django.core.files.storage import default_storage
|
||||
from django.db.models import Avg
|
||||
|
||||
from bookwyrm import models, settings
|
||||
|
@ -325,6 +326,10 @@ def save_and_cleanup(image, instance=None):
|
|||
uuid = uuid4()
|
||||
file_name = f"{instance.id}-{uuid}.jpg"
|
||||
|
||||
# Clean up old file before saving
|
||||
if file_name and default_storage.exists(file_name):
|
||||
default_storage.delete(file_name)
|
||||
|
||||
# Save
|
||||
image.save(image_buffer, format="jpeg", quality=75)
|
||||
|
||||
|
|
Loading…
Reference in a new issue