@@ -268,31 +268,56 @@ def delete_images(project, image_names):
268268 :param image_names: to be deleted images' names. If None, all the images will be deleted
269269 :type image_names: list of strs
270270 """
271+ project , project_folder = get_project_and_folder_metadata (project )
272+ params = {"team_id" : project ["team_id" ], "project_id" : project ["id" ]}
271273 if image_names is None :
272- images = search_images (project , return_metadata = True )
274+ if project_folder is not None :
275+ data = {"folder_id" : project_folder ["id" ]}
276+ else :
277+ data = {"folder_id" : get_project_root_folder_id (project )}
278+ response = _api .send_request (
279+ req_type = 'PUT' ,
280+ path = '/image/delete/images' ,
281+ params = params ,
282+ json_req = data
283+ )
284+ if not response .ok :
285+ raise SABaseException (
286+ response .status_code , "Couldn't delete images " + response .text
287+ )
273288 else :
289+ NUM_TO_SEND = 1000
274290 if not isinstance (image_names , list ):
275291 raise SABaseException (
276292 0 , "image_names should be a list of strs or None"
277293 )
278294 images = get_image_metadata (
279295 project , image_names , return_dict_on_single_output = False
280296 )
281- project , _ = get_project_and_folder_metadata (project )
282-
283- params = {"team_id" : project ["team_id" ], "project_id" : project ["id" ]}
284- data = {"image_ids" : [image ["id" ] for image in images ]}
285- response = _api .send_request (
286- req_type = 'PUT' ,
287- path = '/image/delete/images' ,
288- params = params ,
289- json_req = data
297+ for start_index in range (0 , len (image_names ), NUM_TO_SEND ):
298+ data = {
299+ "image_ids" :
300+ [
301+ image ["id" ]
302+ for image in images [start_index :start_index +
303+ NUM_TO_SEND ]
304+ ]
305+ }
306+ response = _api .send_request (
307+ req_type = 'PUT' ,
308+ path = '/image/delete/images' ,
309+ params = params ,
310+ json_req = data
311+ )
312+ if not response .ok :
313+ raise SABaseException (
314+ response .status_code ,
315+ "Couldn't delete images " + response .text
316+ )
317+ logger .info (
318+ "Images deleted in project %s%s" , project ["name" ],
319+ "" if project_folder is None else "/" + project_folder ["name" ]
290320 )
291- if not response .ok :
292- raise SABaseException (
293- response .status_code , "Couldn't delete images " + response .text
294- )
295- logger .info ("Images %s deleted in project %s" , image_names , project ["name" ])
296321
297322
298323def move_images (
0 commit comments