]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Removes last vestiges of PNG from the tests, code, docs and samples
authorTrenton Holmes <holmes.trenton@gmail.com>
Sat, 11 Jun 2022 21:15:27 +0000 (14:15 -0700)
committerTrenton Holmes <holmes.trenton@gmail.com>
Sat, 11 Jun 2022 21:20:50 +0000 (14:20 -0700)
19 files changed:
Dockerfile
docs/administration.rst
src/documents/__init__.py
src/documents/checks.py
src/documents/management/commands/document_exporter.py
src/documents/management/commands/document_thumbnails.py
src/documents/tests/samples/documents/thumbnails/0000001.png [deleted file]
src/documents/tests/samples/documents/thumbnails/0000001.webp [new file with mode: 0644]
src/documents/tests/samples/documents/thumbnails/0000002.png [deleted file]
src/documents/tests/samples/documents/thumbnails/0000002.webp [new file with mode: 0644]
src/documents/tests/samples/documents/thumbnails/0000003.png [deleted file]
src/documents/tests/samples/documents/thumbnails/0000003.webp [new file with mode: 0644]
src/documents/tests/samples/documents/thumbnails/0000004.png.gpg [deleted file]
src/documents/tests/samples/documents/thumbnails/0000004.webp.gpg [new file with mode: 0644]
src/documents/tests/test_api.py
src/documents/tests/test_consumer.py
src/documents/tests/test_management.py
src/documents/tests/test_sanity_check.py
src/documents/views.py

index fda47998cd287b8e3a88c68321105b7d0959415a..630cd367c8d94674dd7592f98457f619691bbb3e 100644 (file)
@@ -83,8 +83,6 @@ ARG RUNTIME_PACKAGES="\
   postgresql-client \
   # For Numpy
   libatlas3-base \
-  # thumbnail size reduction
-  pngquant \
   # OCRmyPDF dependencies
   tesseract-ocr \
   tesseract-ocr-eng \
index f1930256c2019671aae219b50b54b9eba98b8652..dfb88ff8086e629dec9fc14180b3cab85a0c9698 100644 (file)
@@ -518,15 +518,3 @@ Basic usage to disable encryption of your document store:
 .. code::
 
     decrypt_documents [--passphrase SECR3TP4SSPHRA$E]
-
-Managing thumbnail format
-===================
-
-Document thumbnails were originally created as PNG format.  Newly
-uploaded documents are now using WebP to reduce both storage space and
-page loading times.  To convert older PNG format thumbnails to WebP
-run:
-
-.. code::
-
-    convert_thumbnails
index 005c6e2fbbd5ea08779892059c321329098ac408..dc94f2bddee3064d67ba399b44bd106e13ca0761 100644 (file)
@@ -1,6 +1,5 @@
 # this is here so that django finds the checks.
 from .checks import changed_password_check
 from .checks import parser_check
-from .checks import png_thumbnail_check
 
-__all__ = ["changed_password_check", "parser_check", "png_thumbnail_check"]
+__all__ = ["changed_password_check", "parser_check"]
index 0a9511bd607560ed72989f89d8f4aa32f1244176..a014a0ac2b91203e7bf535845330bd5d04676e54 100644 (file)
@@ -1,9 +1,7 @@
 import textwrap
-from pathlib import Path
 
 from django.conf import settings
 from django.core.checks import Error
-from django.core.checks import Info
 from django.core.checks import register
 from django.core.exceptions import FieldError
 from django.db.utils import OperationalError
@@ -68,23 +66,3 @@ def parser_check(app_configs, **kwargs):
         ]
     else:
         return []
-
-
-@register()
-def png_thumbnail_check(app_configs, **kwargs):
-    from documents.models import Document
-
-    try:
-        documents = Document.objects.all()
-        for document in documents:
-            existing_thumbnail = Path(document.thumbnail_path).resolve()
-            if existing_thumbnail.suffix == ".png":
-                return [
-                    Info(
-                        "PNG thumbnails found, consider running convert_thumbnails "
-                        "to convert to WebP",
-                    ),
-                ]
-        return []
-    except (OperationalError, ProgrammingError, FieldError):
-        return []  # No documents table yet
index 4bddd51b88f1b61f51d987d4ea92c7663a9837b3..526d59368a6cebb109b44503ed177354c307e18a 100644 (file)
@@ -189,7 +189,7 @@ class Command(BaseCommand):
             original_target = os.path.join(self.target, original_name)
             document_dict[EXPORTER_FILE_NAME] = original_name
 
-            thumbnail_name = base_name + "-thumbnail.png"
+            thumbnail_name = base_name + "-thumbnail.webp"
             thumbnail_target = os.path.join(self.target, thumbnail_name)
             document_dict[EXPORTER_THUMBNAIL_NAME] = thumbnail_name
 
index 535a0f670f99e7225e106f9fcb82e9550b0bbf93..b56bc00428a01bfe363ffdad8cc357ee87f900a8 100644 (file)
@@ -1,7 +1,6 @@
 import logging
 import multiprocessing
 import shutil
-from pathlib import Path
 
 import tqdm
 from django import db
@@ -23,12 +22,6 @@ def _process_document(doc_in):
 
     try:
 
-        existing_thumbnail = Path(document.thumbnail_path).resolve()
-
-        # Remove an existing PNG format thumbnail, if it existed
-        if existing_thumbnail.exists() and existing_thumbnail.suffix == ".png":
-            existing_thumbnail.unlink()
-
         thumb = parser.get_thumbnail(
             document.source_path,
             document.mime_type,
diff --git a/src/documents/tests/samples/documents/thumbnails/0000001.png b/src/documents/tests/samples/documents/thumbnails/0000001.png
deleted file mode 100644 (file)
index a3a7684..0000000
Binary files a/src/documents/tests/samples/documents/thumbnails/0000001.png and /dev/null differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000001.webp b/src/documents/tests/samples/documents/thumbnails/0000001.webp
new file mode 100644 (file)
index 0000000..a7ff623
Binary files /dev/null and b/src/documents/tests/samples/documents/thumbnails/0000001.webp differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000002.png b/src/documents/tests/samples/documents/thumbnails/0000002.png
deleted file mode 100644 (file)
index a3a7684..0000000
Binary files a/src/documents/tests/samples/documents/thumbnails/0000002.png and /dev/null differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000002.webp b/src/documents/tests/samples/documents/thumbnails/0000002.webp
new file mode 100644 (file)
index 0000000..a7ff623
Binary files /dev/null and b/src/documents/tests/samples/documents/thumbnails/0000002.webp differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000003.png b/src/documents/tests/samples/documents/thumbnails/0000003.png
deleted file mode 100644 (file)
index a3a7684..0000000
Binary files a/src/documents/tests/samples/documents/thumbnails/0000003.png and /dev/null differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000003.webp b/src/documents/tests/samples/documents/thumbnails/0000003.webp
new file mode 100644 (file)
index 0000000..a7ff623
Binary files /dev/null and b/src/documents/tests/samples/documents/thumbnails/0000003.webp differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000004.png.gpg b/src/documents/tests/samples/documents/thumbnails/0000004.png.gpg
deleted file mode 100644 (file)
index 8a61a91..0000000
Binary files a/src/documents/tests/samples/documents/thumbnails/0000004.png.gpg and /dev/null differ
diff --git a/src/documents/tests/samples/documents/thumbnails/0000004.webp.gpg b/src/documents/tests/samples/documents/thumbnails/0000004.webp.gpg
new file mode 100644 (file)
index 0000000..3abc69d
Binary files /dev/null and b/src/documents/tests/samples/documents/thumbnails/0000004.webp.gpg differ
index 24bdc3a5011af2f834541c3656b22a6b2a8cb690..6d659e66dead1293b6891e4ab85920098e5444a7 100644 (file)
@@ -176,7 +176,7 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
         )
 
         with open(
-            os.path.join(self.dirs.thumbnail_dir, f"{doc.pk:07d}.png"),
+            os.path.join(self.dirs.thumbnail_dir, f"{doc.pk:07d}.webp"),
             "wb",
         ) as f:
             f.write(content_thumbnail)
@@ -1022,7 +1022,7 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
             "samples",
             "documents",
             "thumbnails",
-            "0000001.png",
+            "0000001.webp",
         )
         archive_file = os.path.join(os.path.dirname(__file__), "samples", "simple.pdf")
 
index a770d3ff694eb6cfd530ad1a588c4cfd10555ef9..48f19590371b047c869811ba62951b355bb9535c 100644 (file)
@@ -180,7 +180,7 @@ class DummyParser(DocumentParser):
 
     def __init__(self, logging_group, scratch_dir, archive_path):
         super().__init__(logging_group, None)
-        _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir)
+        _, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=scratch_dir)
         self.archive_path = archive_path
 
     def get_thumbnail(self, document_path, mime_type, file_name=None):
@@ -199,7 +199,7 @@ class CopyParser(DocumentParser):
 
     def __init__(self, logging_group, progress_callback=None):
         super().__init__(logging_group, progress_callback)
-        _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=self.tempdir)
+        _, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=self.tempdir)
 
     def parse(self, document_path, mime_type, file_name=None):
         self.text = "The text"
@@ -214,7 +214,7 @@ class FaultyParser(DocumentParser):
 
     def __init__(self, logging_group, scratch_dir):
         super().__init__(logging_group)
-        _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir)
+        _, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=scratch_dir)
 
     def get_thumbnail(self, document_path, mime_type, file_name=None):
         return self.fake_thumb
@@ -230,6 +230,8 @@ def fake_magic_from_file(file, mime=False):
             return "application/pdf"
         elif os.path.splitext(file)[1] == ".png":
             return "image/png"
+        elif os.path.splitext(file)[1] == ".webp":
+            return "image/webp"
         else:
             return "unknown"
     else:
index 65ed36ff97414207d1bd6f23ee153e2fb88bdfba..76a5459b52f63cbbcf4e03fc463f9a5898593313 100644 (file)
@@ -150,9 +150,9 @@ class TestDecryptDocuments(TestCase):
                 "samples",
                 "documents",
                 "thumbnails",
-                f"0000004.png.gpg",
+                f"0000004.webp.gpg",
             ),
-            os.path.join(thumb_dir, f"{doc.id:07}.png.gpg"),
+            os.path.join(thumb_dir, f"{doc.id:07}.webp.gpg"),
         )
 
         call_command("decrypt_documents")
index 5ebedd908b6ab7523ba050f323f7d4ea957ce0d8..9bb424cbc750cd7ff8427813cbbf34bb73d78a1b 100644 (file)
@@ -42,9 +42,9 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
                     "samples",
                     "documents",
                     "thumbnails",
-                    "0000001.png",
+                    "0000001.webp",
                 ),
-                os.path.join(self.dirs.thumbnail_dir, "0000001.png"),
+                os.path.join(self.dirs.thumbnail_dir, "0000001.webp"),
             )
 
         return Document.objects.create(
index bcd2958f8a9fcf84329ca9e22fde815e93fb3ee8..8fa86b4ca50f8fbfa3b8c6d8e0a62fbd148b8817 100644 (file)
@@ -362,11 +362,7 @@ class DocumentViewSet(
                 handle = doc.thumbnail_file
             # TODO: Send ETag information and use that to send new thumbnails
             #  if available
-            thumbnail_path = doc.thumbnail_path
-            if os.path.splitext(thumbnail_path)[1] == ".webp":
-                content_type = "image/webp"
-            else:
-                content_type = "image/png"
+            content_type = "image/webp"
 
             return HttpResponse(handle, content_type=content_type)
         except (FileNotFoundError, Document.DoesNotExist):