mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Logs the errors during thumbnail generation, updates default to be WebP
This commit is contained in:
parent
7aa72f768f
commit
1a87c730bc
@ -166,11 +166,11 @@ def run_convert(
|
|||||||
raise ParseError(f"Convert failed at {args}")
|
raise ParseError(f"Convert failed at {args}")
|
||||||
|
|
||||||
|
|
||||||
def get_default_thumbnail() -> str:
|
def get_default_thumbnail() -> Path:
|
||||||
"""
|
"""
|
||||||
Returns the path to a generic thumbnail
|
Returns the path to a generic thumbnail
|
||||||
"""
|
"""
|
||||||
return os.path.join(os.path.dirname(__file__), "resources", "document.png")
|
return (Path(__file__).parent / "resources" / "document.webp").resolve()
|
||||||
|
|
||||||
|
|
||||||
def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -> str:
|
def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -> str:
|
||||||
@ -183,12 +183,13 @@ def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -
|
|||||||
"to ghostscript. Check your /etc/ImageMagick-x/policy.xml!",
|
"to ghostscript. Check your /etc/ImageMagick-x/policy.xml!",
|
||||||
extra={"group": logging_group},
|
extra={"group": logging_group},
|
||||||
)
|
)
|
||||||
|
# Ghostscript doesn't handle WebP outputs
|
||||||
gs_out_path = os.path.join(temp_dir, "gs_out.png")
|
gs_out_path = os.path.join(temp_dir, "gs_out.png")
|
||||||
cmd = [settings.GS_BINARY, "-q", "-sDEVICE=pngalpha", "-o", gs_out_path, in_path]
|
cmd = [settings.GS_BINARY, "-q", "-sDEVICE=pngalpha", "-o", gs_out_path, in_path]
|
||||||
try:
|
try:
|
||||||
if not subprocess.Popen(cmd).wait() == 0:
|
if not subprocess.Popen(cmd).wait() == 0:
|
||||||
raise ParseError(f"Thumbnail (gs) failed at {cmd}")
|
raise ParseError(f"Thumbnail (gs) failed at {cmd}")
|
||||||
# then run convert on the output from gs
|
# then run convert on the output from gs to make WebP
|
||||||
run_convert(
|
run_convert(
|
||||||
density=300,
|
density=300,
|
||||||
scale="500x5000>",
|
scale="500x5000>",
|
||||||
@ -203,11 +204,12 @@ def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -
|
|||||||
|
|
||||||
return out_path
|
return out_path
|
||||||
|
|
||||||
except ParseError:
|
except ParseError as e:
|
||||||
|
logger.error(f"Unable to make thumbnail with Ghostscript: {e}")
|
||||||
# The caller might expect a generated thumbnail that can be moved,
|
# The caller might expect a generated thumbnail that can be moved,
|
||||||
# so we need to copy it before it gets moved.
|
# so we need to copy it before it gets moved.
|
||||||
# https://github.com/paperless-ngx/paperless-ngx/issues/3631
|
# https://github.com/paperless-ngx/paperless-ngx/issues/3631
|
||||||
default_thumbnail_path = os.path.join(temp_dir, "document.png")
|
default_thumbnail_path = os.path.join(temp_dir, "document.webp")
|
||||||
copy_file_with_basic_stats(get_default_thumbnail(), default_thumbnail_path)
|
copy_file_with_basic_stats(get_default_thumbnail(), default_thumbnail_path)
|
||||||
return default_thumbnail_path
|
return default_thumbnail_path
|
||||||
|
|
||||||
@ -231,7 +233,8 @@ def make_thumbnail_from_pdf(in_path, temp_dir, logging_group=None) -> str:
|
|||||||
output_file=out_path,
|
output_file=out_path,
|
||||||
logging_group=logging_group,
|
logging_group=logging_group,
|
||||||
)
|
)
|
||||||
except ParseError:
|
except ParseError as e:
|
||||||
|
logger.error(f"Unable to make thumbnail with convert: {e}")
|
||||||
out_path = make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group)
|
out_path = make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group)
|
||||||
|
|
||||||
return out_path
|
return out_path
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
BIN
src/documents/resources/document.webp
Normal file
BIN
src/documents/resources/document.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
@ -820,7 +820,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
|
|||||||
|
|
||||||
@override_settings(FILENAME_FORMAT="{title}")
|
@override_settings(FILENAME_FORMAT="{title}")
|
||||||
def test_archive_deleted2(self):
|
def test_archive_deleted2(self):
|
||||||
original = os.path.join(settings.ORIGINALS_DIR, "document.png")
|
original = os.path.join(settings.ORIGINALS_DIR, "document.webp")
|
||||||
original2 = os.path.join(settings.ORIGINALS_DIR, "0000001.pdf")
|
original2 = os.path.join(settings.ORIGINALS_DIR, "0000001.pdf")
|
||||||
archive = os.path.join(settings.ARCHIVE_DIR, "0000001.pdf")
|
archive = os.path.join(settings.ARCHIVE_DIR, "0000001.pdf")
|
||||||
Path(original).touch()
|
Path(original).touch()
|
||||||
@ -828,9 +828,9 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
|
|||||||
Path(archive).touch()
|
Path(archive).touch()
|
||||||
|
|
||||||
doc1 = Document.objects.create(
|
doc1 = Document.objects.create(
|
||||||
mime_type="image/png",
|
mime_type="image/webp",
|
||||||
title="document",
|
title="document",
|
||||||
filename="document.png",
|
filename="document.webp",
|
||||||
checksum="A",
|
checksum="A",
|
||||||
archive_checksum="B",
|
archive_checksum="B",
|
||||||
archive_filename="0000001.pdf",
|
archive_filename="0000001.pdf",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user