@@ -153,7 +153,6 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
153153
154154 @staticmethod
155155 def is_preview_file (file_path ) -> bool :
156-
157156 file_suffix = file_path .suffix .lower ()
158157 is_picture_file = file_suffix in [".png" , ".jpg" , ".jpeg" , ".bmp" , ".gif" ]
159158
@@ -253,9 +252,8 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
253252 continue
254253
255254 if self .is_preview_file (file ):
256- file_stem = file .stem .lower ().replace ("_preview" , "" )
257- potential_previews [file_stem ] = FileInfo (file ,
258- PurePosixPath (file .relative_to (config .assets_path )))
255+ file_stem = self .remove_preview_suffix (file )
256+ potential_previews [file_stem ] = FileInfo (file , PurePosixPath (file .relative_to (config .assets_path )))
259257
260258 for file in files :
261259 if self .is_directory_path (file ):
@@ -284,17 +282,32 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
284282
285283 @staticmethod
286284 def is_preview_file (file_path ) -> bool :
287- file_suffix = file_path .suffix
288- is_picture_file = file_suffix in [".png" , ".jpg" , ".jpeg" , ".bmp" , ".gif" ]
285+ file_suffix = file_path .suffix . lower ()
286+ is_picture_file = file_suffix in [".png" , ".jpg" , ".jpeg" , ".bmp" , ".gif" ]
289287
290288 file_stem = file_path .stem .lower ()
289+ file_name_is_preview = file_stem in ["preview" , "previews" , "thumbnail" , "thumbnails" ]
291290
292- return file_stem .endswith ("_preview" ) and is_picture_file
291+ file_parent_folder = file_path .parent .name .lower ()
292+ parent_folder_is_preview = file_parent_folder in ["preview" , "previews" , "thumbnail" , "thumbnails" ]
293+
294+ return is_picture_file and file_name_is_preview or is_picture_file and parent_folder_is_preview
293295
294296 @staticmethod
295297 def is_directory_path (file_path ) -> bool :
296298 return len (file_path .name .split ("/" )[- 1 ].split ("." )) == 1
297299
300+ @staticmethod
301+ def remove_preview_suffix (file_path ) -> str :
302+ file_stem = file_path .stem .lower ()
303+
304+ for suffix in ["preview" , "previews" , "thumbnail" , "thumbnails" ]:
305+ if file_stem .endswith (suffix ):
306+ new_stem = file_stem .replace (suffix , "" )
307+ break
308+
309+ return file_stem
310+
298311
299312class CsvAssetMapper (AssetMapper ):
300313
0 commit comments