]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Corrects the logic of thumbnail path to account for both getting existing path or...
authorTrenton Holmes <holmes.trenton@gmail.com>
Fri, 10 Jun 2022 14:59:22 +0000 (07:59 -0700)
committerTrenton Holmes <holmes.trenton@gmail.com>
Fri, 10 Jun 2022 14:59:22 +0000 (07:59 -0700)
src/documents/models.py

index bd69aaff13db13e179073c7ab69511c05feafe36..d889ef2c53cb4f53503fe886c289717249535f69 100644 (file)
@@ -300,10 +300,26 @@ class Document(models.Model):
             png_file_name += ".gpg"
             webp_file_name += ".gpg"
 
-        thumb = os.path.join(settings.THUMBNAIL_DIR, webp_file_name)
-
-        if not os.path.exists(thumb):
-            thumb = os.path.join(settings.THUMBNAIL_DIR, png_file_name)
+        # This property is used to both generate the file path
+        # and locate the file itself
+        # Hence why this looks a little weird
+
+        webp_file_path = os.path.join(settings.THUMBNAIL_DIR, webp_file_name)
+        png_file_path = thumb = os.path.join(settings.THUMBNAIL_DIR, png_file_name)
+
+        # 1. Assume the thumbnail is WebP
+
+        if not os.path.exists(webp_file_path):
+            # 2. If WebP doesn't exist, check PNG
+            if not os.path.exists(png_file_path):
+                # 3. If PNG doesn't exist, filename is being constructed, return WebP
+                thumb = webp_file_path
+            else:
+                # 2.1 - PNG file exists, return path to it
+                thumb = png_file_name
+        else:
+            # 1.1 - WebP file exists, return path to it
+            thumb = webp_file_path
         return thumb
 
     @property