@@ -412,7 +412,8 @@ def convert_data(pro, path=None):
412412 if key in item_path_not_existed :
413413 continue
414414 key_path = handle_generate_key_path (key )
415- if value or key_path [0 ] in ['file_path' , 'thumbnail_path' ]:
415+ if value or key_path [0 ] in ['file_path' , 'thumbnail_path' ] \
416+ or key_path [- 1 ] == 'filename' :
416417 set_nested_item (result , key_path , value )
417418
418419 convert_data (result )
@@ -2734,10 +2735,14 @@ def handle_check_file_content(record, data_path):
27342735 errors = []
27352736 warnings = []
27362737
2738+ file_paths = record .get ('file_path' , [])
2739+ # check consistence between file_path and filename
2740+ filenames = get_filenames_from_metadata (record ['metadata' ])
2741+ errors .extend (handle_check_filename_consistence (file_paths , filenames ))
2742+
2743+ # check if file_path exists
27372744 error , warning = handle_check_file_path (
2738- record .get ('file_path' , []),
2739- data_path ,
2740- record ['status' ] == 'new' )
2745+ file_paths , data_path , record ['status' ] == 'new' )
27412746 if error :
27422747 errors .append (error )
27432748 if warning :
@@ -2778,3 +2783,53 @@ def handle_check_thumbnail(record, data_path):
27782783 warnings .append (warning )
27792784
27802785 return errors , warnings
2786+
2787+
2788+ def get_filenames_from_metadata (metadata ):
2789+ """Check thumbnails metadata.
2790+
2791+ :argument
2792+ metadata -- {dict} record metadata.
2793+ :return
2794+ filenames -- {list} List filename data.
2795+ """
2796+ filenames = []
2797+ file_meta_ids = []
2798+ for key , val in metadata .items ():
2799+ if isinstance (val , list ):
2800+ for item in val :
2801+ if isinstance (item , dict ) and 'filename' in item :
2802+ file_meta_ids .append (key )
2803+ break
2804+
2805+ count = 0
2806+ for _id in file_meta_ids :
2807+ for file in metadata [_id ]:
2808+ data = {
2809+ 'id' : '.metadata.{}[{}].filename' .format (_id , count ),
2810+ 'filename' : file .get ('filename' , '' )
2811+ }
2812+ filenames .append (data )
2813+ count += 1
2814+
2815+ return filenames
2816+
2817+
2818+ def handle_check_filename_consistence (file_paths , meta_filenames ):
2819+ """Check thumbnails metadata.
2820+
2821+ :argument
2822+ file_paths -- {list} List file_path.
2823+ meta_filenames -- {list} List filename from metadata.
2824+ :return
2825+ errors -- {list} List errors.
2826+ """
2827+ errors = []
2828+ msg = _ ('The file name specified in {} and {} do not match.' )
2829+ for idx , path in enumerate (file_paths ):
2830+ meta_filename = meta_filenames [idx ]
2831+ if path and path .split ('/' )[- 1 ] != meta_filename ['filename' ]:
2832+ errors .append (msg .format (
2833+ 'file_path[{}]' .format (idx ), meta_filename ['id' ]))
2834+
2835+ return errors
0 commit comments