Adds information system check for PNG thumbnail existence

This commit is contained in:
Trenton Holmes 2022-06-10 08:56:55 -07:00
parent 34192349be
commit 12cdcf7681
2 changed files with 24 additions and 2 deletions

View File

@ -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"]

View File

@ -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