From 12cdcf76816966af03fb452a3862710b8b1b030e Mon Sep 17 00:00:00 2001 From: Trenton Holmes Date: Fri, 10 Jun 2022 08:56:55 -0700 Subject: [PATCH] Adds information system check for PNG thumbnail existence --- src/documents/__init__.py | 3 ++- src/documents/checks.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/documents/__init__.py b/src/documents/__init__.py index dc94f2bdd..005c6e2fb 100644 --- a/src/documents/__init__.py +++ b/src/documents/__init__.py @@ -1,5 +1,6 @@ # 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"] +__all__ = ["changed_password_check", "parser_check", "png_thumbnail_check"] diff --git a/src/documents/checks.py b/src/documents/checks.py index 4ac49a2c2..0a9511bd6 100644 --- a/src/documents/checks.py +++ b/src/documents/checks.py @@ -1,7 +1,9 @@ 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 @@ -11,7 +13,6 @@ from documents.signals import document_consumer_declaration @register() def changed_password_check(app_configs, **kwargs): - from documents.models import Document from paperless.db import GnuPG @@ -67,3 +68,23 @@ 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