diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index c06b17bf..fe2f7467 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -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/ diff --git a/bookwyrm/thumbnail_generation.py b/bookwyrm/thumbnail_generation.py new file mode 100644 index 00000000..64f7ebef --- /dev/null +++ b/bookwyrm/thumbnail_generation.py @@ -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()