mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-27 02:20:31 +00:00
Merge pull request #1769 from joachimesque/thumbnail-generation-strategy
Change thumbnail generation strategy
This commit is contained in:
commit
6492ca2941
2 changed files with 21 additions and 0 deletions
|
@ -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/
|
||||
|
|
20
bookwyrm/thumbnail_generation.py
Normal file
20
bookwyrm/thumbnail_generation.py
Normal 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()
|
Loading…
Reference in a new issue