33import os
44import shutil
55from contextlib import contextmanager
6+ from pathlib import Path
67
78import tqdm
89from django .conf import settings
1415from django .db .models .signals import m2m_changed
1516from django .db .models .signals import post_save
1617from documents .models import Document
18+ from documents .parsers import run_convert
1719from documents .settings import EXPORTER_ARCHIVE_NAME
1820from documents .settings import EXPORTER_FILE_NAME
1921from documents .settings import EXPORTER_THUMBNAIL_NAME
@@ -192,7 +194,7 @@ def _import_files_from_manifest(self, progress_bar_disable):
192194 document_path = os .path .join (self .source , doc_file )
193195
194196 thumb_file = record [EXPORTER_THUMBNAIL_NAME ]
195- thumbnail_path = os .path .join (self .source , thumb_file )
197+ thumbnail_path = Path ( os .path .join (self .source , thumb_file )). resolve ( )
196198
197199 if EXPORTER_ARCHIVE_NAME in record :
198200 archive_file = record [EXPORTER_ARCHIVE_NAME ]
@@ -209,7 +211,20 @@ def _import_files_from_manifest(self, progress_bar_disable):
209211 create_source_path_directory (document .source_path )
210212
211213 shutil .copy2 (document_path , document .source_path )
212- shutil .copy2 (thumbnail_path , document .thumbnail_path )
214+
215+ if thumbnail_path .suffix in {".png" , ".PNG" }:
216+ run_convert (
217+ density = 300 ,
218+ scale = "500x5000>" ,
219+ alpha = "remove" ,
220+ strip = True ,
221+ trim = False ,
222+ auto_orient = True ,
223+ input_file = f"{ thumbnail_path } [0]" ,
224+ output_file = str (document .thumbnail_path ),
225+ )
226+ else :
227+ shutil .copy2 (thumbnail_path , document .thumbnail_path )
213228 if archive_path :
214229 create_source_path_directory (document .archive_path )
215230 # TODO: this assumes that the export is valid and
0 commit comments