mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	fix a bug with thumbnail generation when TIKA was enabled
This commit is contained in:
		| @@ -241,7 +241,7 @@ class Consumer(LoggingMixin): | |||||||
|             self._send_progress(70, 100, 'WORKING', |             self._send_progress(70, 100, 'WORKING', | ||||||
|                                 MESSAGE_GENERATING_THUMBNAIL) |                                 MESSAGE_GENERATING_THUMBNAIL) | ||||||
|             thumbnail = document_parser.get_optimised_thumbnail( |             thumbnail = document_parser.get_optimised_thumbnail( | ||||||
|                 self.path, mime_type) |                 self.path, mime_type, self.filename) | ||||||
|  |  | ||||||
|             text = document_parser.get_text() |             text = document_parser.get_text() | ||||||
|             date = document_parser.get_date() |             date = document_parser.get_date() | ||||||
|   | |||||||
| @@ -22,7 +22,10 @@ def _process_document(doc_in): | |||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         thumb = parser.get_optimised_thumbnail( |         thumb = parser.get_optimised_thumbnail( | ||||||
|             document.source_path, document.mime_type) |             document.source_path, | ||||||
|  |             document.mime_type, | ||||||
|  |             document.get_public_filename() | ||||||
|  |         ) | ||||||
|  |  | ||||||
|         shutil.move(thumb, document.thumbnail_path) |         shutil.move(thumb, document.thumbnail_path) | ||||||
|     finally: |     finally: | ||||||
|   | |||||||
| @@ -288,14 +288,17 @@ class DocumentParser(LoggingMixin): | |||||||
|     def get_archive_path(self): |     def get_archive_path(self): | ||||||
|         return self.archive_path |         return self.archive_path | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         """ |         """ | ||||||
|         Returns the path to a file we can use as a thumbnail for this document. |         Returns the path to a file we can use as a thumbnail for this document. | ||||||
|         """ |         """ | ||||||
|         raise NotImplementedError() |         raise NotImplementedError() | ||||||
|  |  | ||||||
|     def get_optimised_thumbnail(self, document_path, mime_type): |     def get_optimised_thumbnail(self, | ||||||
|         thumbnail = self.get_thumbnail(document_path, mime_type) |                                 document_path, | ||||||
|  |                                 mime_type, | ||||||
|  |                                 file_name=None): | ||||||
|  |         thumbnail = self.get_thumbnail(document_path, mime_type, file_name) | ||||||
|         if settings.OPTIMIZE_THUMBNAILS: |         if settings.OPTIMIZE_THUMBNAILS: | ||||||
|             out_path = os.path.join(self.tempdir, "thumb_optipng.png") |             out_path = os.path.join(self.tempdir, "thumb_optipng.png") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -167,7 +167,7 @@ class TestFieldPermutations(TestCase): | |||||||
|  |  | ||||||
| class DummyParser(DocumentParser): | class DummyParser(DocumentParser): | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         # not important during tests |         # not important during tests | ||||||
|         raise NotImplementedError() |         raise NotImplementedError() | ||||||
|  |  | ||||||
| @@ -176,7 +176,7 @@ class DummyParser(DocumentParser): | |||||||
|         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) |         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) | ||||||
|         self.archive_path = archive_path |         self.archive_path = archive_path | ||||||
|  |  | ||||||
|     def get_optimised_thumbnail(self, document_path, mime_type): |     def get_optimised_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         return self.fake_thumb |         return self.fake_thumb | ||||||
|  |  | ||||||
|     def parse(self, document_path, mime_type, file_name=None): |     def parse(self, document_path, mime_type, file_name=None): | ||||||
| @@ -185,10 +185,10 @@ class DummyParser(DocumentParser): | |||||||
|  |  | ||||||
| class CopyParser(DocumentParser): | class CopyParser(DocumentParser): | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         return self.fake_thumb |         return self.fake_thumb | ||||||
|  |  | ||||||
|     def get_optimised_thumbnail(self, document_path, mime_type): |     def get_optimised_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         return self.fake_thumb |         return self.fake_thumb | ||||||
|  |  | ||||||
|     def __init__(self, logging_group, progress_callback=None): |     def __init__(self, logging_group, progress_callback=None): | ||||||
| @@ -203,7 +203,7 @@ class CopyParser(DocumentParser): | |||||||
|  |  | ||||||
| class FaultyParser(DocumentParser): | class FaultyParser(DocumentParser): | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         # not important during tests |         # not important during tests | ||||||
|         raise NotImplementedError() |         raise NotImplementedError() | ||||||
|  |  | ||||||
| @@ -211,7 +211,7 @@ class FaultyParser(DocumentParser): | |||||||
|         super(FaultyParser, self).__init__(logging_group) |         super(FaultyParser, self).__init__(logging_group) | ||||||
|         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) |         _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=scratch_dir) | ||||||
|  |  | ||||||
|     def get_optimised_thumbnail(self, document_path, mime_type): |     def get_optimised_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         return self.fake_thumb |         return self.fake_thumb | ||||||
|  |  | ||||||
|     def parse(self, document_path, mime_type, file_name=None): |     def parse(self, document_path, mime_type, file_name=None): | ||||||
|   | |||||||
| @@ -68,7 +68,7 @@ class TestParserDiscovery(TestCase): | |||||||
|             ) |             ) | ||||||
|  |  | ||||||
|  |  | ||||||
| def fake_get_thumbnail(self, path, mimetype): | def fake_get_thumbnail(self, path, mimetype, file_name): | ||||||
|     return os.path.join(os.path.dirname(__file__), "examples", "no-text.png") |     return os.path.join(os.path.dirname(__file__), "examples", "no-text.png") | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -89,15 +89,15 @@ class TestBaseParser(TestCase): | |||||||
|     def test_get_optimised_thumbnail(self): |     def test_get_optimised_thumbnail(self): | ||||||
|         parser = DocumentParser(None) |         parser = DocumentParser(None) | ||||||
|  |  | ||||||
|         parser.get_optimised_thumbnail("any", "not important") |         parser.get_optimised_thumbnail("any", "not important", "document.pdf") | ||||||
|  |  | ||||||
|     @mock.patch("documents.parsers.DocumentParser.get_thumbnail", fake_get_thumbnail) |     @mock.patch("documents.parsers.DocumentParser.get_thumbnail", fake_get_thumbnail) | ||||||
|     @override_settings(OPTIMIZE_THUMBNAILS=False) |     @override_settings(OPTIMIZE_THUMBNAILS=False) | ||||||
|     def test_get_optimised_thumb_disabled(self): |     def test_get_optimised_thumb_disabled(self): | ||||||
|         parser = DocumentParser(None) |         parser = DocumentParser(None) | ||||||
|  |  | ||||||
|         path = parser.get_optimised_thumbnail("any", "not important") |         path = parser.get_optimised_thumbnail("any", "not important", "document.pdf") | ||||||
|         self.assertEqual(path, fake_get_thumbnail(None, None, None)) |         self.assertEqual(path, fake_get_thumbnail(None, None, None, None)) | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestParserAvailability(TestCase): | class TestParserAvailability(TestCase): | ||||||
|   | |||||||
| @@ -48,7 +48,7 @@ class RasterisedDocumentParser(DocumentParser): | |||||||
|                     ) |                     ) | ||||||
|         return result |         return result | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         return make_thumbnail_from_pdf( |         return make_thumbnail_from_pdf( | ||||||
|             document_path, self.tempdir, self.logging_group) |             document_path, self.tempdir, self.logging_group) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ class TextDocumentParser(DocumentParser): | |||||||
|  |  | ||||||
|     logging_name = "paperless.parsing.text" |     logging_name = "paperless.parsing.text" | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|  |  | ||||||
|         def read_text(): |         def read_text(): | ||||||
|             with open(document_path, 'r') as src: |             with open(document_path, 'r') as src: | ||||||
|   | |||||||
| @@ -16,9 +16,9 @@ class TikaDocumentParser(DocumentParser): | |||||||
|  |  | ||||||
|     logging_name = "paperless.parsing.tika" |     logging_name = "paperless.parsing.tika" | ||||||
|  |  | ||||||
|     def get_thumbnail(self, document_path, mime_type): |     def get_thumbnail(self, document_path, mime_type, file_name=None): | ||||||
|         if not self.archive_path: |         if not self.archive_path: | ||||||
|             self.archive_path = self.convert_to_pdf(document_path) |             self.archive_path = self.convert_to_pdf(document_path, file_name) | ||||||
|  |  | ||||||
|         return make_thumbnail_from_pdf( |         return make_thumbnail_from_pdf( | ||||||
|             self.archive_path, self.tempdir, self.logging_group) |             self.archive_path, self.tempdir, self.logging_group) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler