@@ -153,7 +153,6 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
153
153
154
154
@staticmethod
155
155
def is_preview_file (file_path ) -> bool :
156
-
157
156
file_suffix = file_path .suffix .lower ()
158
157
is_picture_file = file_suffix in [".png" , ".jpg" , ".jpeg" , ".bmp" , ".gif" ]
159
158
@@ -253,9 +252,8 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
253
252
continue
254
253
255
254
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 )))
259
257
260
258
for file in files :
261
259
if self .is_directory_path (file ):
@@ -284,17 +282,32 @@ def map_assets(self, config: ProjectUploaderConfig) -> [AssetInfo]:
284
282
285
283
@staticmethod
286
284
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" ]
289
287
290
288
file_stem = file_path .stem .lower ()
289
+ file_name_is_preview = file_stem in ["preview" , "previews" , "thumbnail" , "thumbnails" ]
291
290
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
293
295
294
296
@staticmethod
295
297
def is_directory_path (file_path ) -> bool :
296
298
return len (file_path .name .split ("/" )[- 1 ].split ("." )) == 1
297
299
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
+
298
311
299
312
class CsvAssetMapper (AssetMapper ):
300
313
0 commit comments