Merge pull request #1769 from joachimesque/thumbnail-generation-strategy

Change thumbnail generation strategy
This commit is contained in:
Mouse Reeve 2022-01-09 12:34:42 -08:00 committed by GitHub
commit 6492ca2941
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -222,6 +222,7 @@ USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)"
# Imagekit generated thumbnails
ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False)
IMAGEKIT_CACHEFILE_DIR = "thumbnails"
IMAGEKIT_DEFAULT_CACHEFILE_STRATEGY = "bookwyrm.thumbnail_generation.Strategy"
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

View file

@ -0,0 +1,20 @@
"""thumbnail generation strategy for django-imagekit"""
class Strategy:
"""
A strategy that generates the image on source saved (Optimistic),
but also on demand, for old images (JustInTime).
"""
def on_source_saved(self, file): # pylint: disable=no-self-use
"""What happens on source saved"""
file.generate()
def on_existence_required(self, file): # pylint: disable=no-self-use
"""What happens on existence required"""
file.generate()
def on_content_required(self, file): # pylint: disable=no-self-use
"""What happens on content required"""
file.generate()