@@ -2485,14 +2485,21 @@ def __init__(
24852485 self ._annotation_status_code = annotation_status_code
24862486 self ._image_quality_in_editor = image_quality_in_editor
24872487 self ._limit = limit
2488+ self ._auth_data = None
24882489
2489- @property
2490- def upload_auth_data (self ):
2491- return self ._backend_service .get_s3_upload_auth_token (
2492- project_id = self ._project .uuid ,
2490+ def validate_auth_data (self ):
2491+ response = self ._backend_service .get_s3_upload_auth_token (
24932492 team_id = self ._project .team_id ,
24942493 folder_id = self ._folder .uuid ,
2494+ project_id = self ._project .uuid ,
24952495 )
2496+ if "error" in response :
2497+ raise AppException (response .get ("error" ))
2498+ self ._auth_data = response
2499+
2500+ @property
2501+ def upload_auth_data (self ):
2502+ return self ._auth_data
24962503
24972504 @property
24982505 def limit (self ):
@@ -2501,15 +2508,16 @@ def limit(self):
25012508 return self ._limit
25022509
25032510 def execute (self ):
2504- extracted_paths = VideoPlugin .extract_frames (
2505- video_path = self ._video_path ,
2506- start_time = self ._start_time ,
2507- end_time = self ._end_time ,
2508- extract_path = self ._extract_path ,
2509- limit = self .limit ,
2510- target_fps = self ._target_fps ,
2511- )
2512- self ._response .data = extracted_paths
2511+ if self .is_valid ():
2512+ extracted_paths = VideoPlugin .extract_frames (
2513+ video_path = self ._video_path ,
2514+ start_time = self ._start_time ,
2515+ end_time = self ._end_time ,
2516+ extract_path = self ._extract_path ,
2517+ limit = self .limit ,
2518+ target_fps = self ._target_fps ,
2519+ )
2520+ self ._response .data = extracted_paths
25132521 return self ._response
25142522
25152523
@@ -4172,14 +4180,18 @@ def validate_project_type(self):
41724180 "The function does not support projects containing videos attached with URLs"
41734181 )
41744182
4183+ def validate_auth_data (self ):
4184+ response = self ._backend_client .get_s3_upload_auth_token (
4185+ team_id = self ._project .team_id ,
4186+ folder_id = self ._folder .uuid ,
4187+ project_id = self ._project .uuid ,
4188+ )
4189+ if "error" in response :
4190+ raise AppException (response .get ("error" ))
4191+ self ._auth_data = response
4192+
41754193 @property
41764194 def auth_data (self ):
4177- if not self ._auth_data :
4178- self ._auth_data = self ._backend_client .get_s3_upload_auth_token (
4179- team_id = self ._project .team_id ,
4180- folder_id = self ._folder .uuid ,
4181- project_id = self ._project .uuid ,
4182- )
41834195 return self ._auth_data
41844196
41854197 @property
@@ -4308,39 +4320,41 @@ def images_to_upload(self):
43084320 return self ._images_to_upload
43094321
43104322 def execute (self ):
4311- images_to_upload , duplications = self .images_to_upload
4312- images_to_upload = images_to_upload [: self .auth_data ["availableImageCount" ]]
4313- uploaded_images = []
4314- failed_images = []
4315- with concurrent .futures .ThreadPoolExecutor (
4316- max_workers = self .MAX_WORKERS
4317- ) as executor :
4318- results = [
4319- executor .submit (self ._upload_image , image_path )
4320- for image_path in images_to_upload
4321- ]
4322- for future in concurrent .futures .as_completed (results ):
4323- processed_image = future .result ()
4324- if processed_image .uploaded and processed_image .entity :
4325- uploaded_images .append (processed_image )
4326- else :
4327- failed_images .append (processed_image .path )
4328- yield
4329-
4330- uploaded = []
4331- for i in range (0 , len (uploaded_images ), 100 ):
4332- response = AttachFileUrlsUseCase (
4333- project = self ._project ,
4334- folder = self ._folder ,
4335- limit = self .auth_data ["availableImageCount" ],
4336- backend_service_provider = self ._backend_client ,
4337- attachments = [image .entity for image in uploaded_images [i : i + 100 ]],
4338- annotation_status = self ._annotation_status ,
4339- ).execute ()
4340-
4341- attachments , duplications = response .data
4342- uploaded .extend (attachments )
4343- uploaded = [image ["name" ] for image in uploaded ]
4344- failed_images = [image .split ("/" )[- 1 ] for image in failed_images ]
4345-
4346- self ._response .data = uploaded , failed_images , duplications
4323+ if self .is_valid ():
4324+ images_to_upload , duplications = self .images_to_upload
4325+ images_to_upload = images_to_upload [: self .auth_data ["availableImageCount" ]]
4326+ uploaded_images = []
4327+ failed_images = []
4328+ with concurrent .futures .ThreadPoolExecutor (
4329+ max_workers = self .MAX_WORKERS
4330+ ) as executor :
4331+ results = [
4332+ executor .submit (self ._upload_image , image_path )
4333+ for image_path in images_to_upload
4334+ ]
4335+ for future in concurrent .futures .as_completed (results ):
4336+ processed_image = future .result ()
4337+ if processed_image .uploaded and processed_image .entity :
4338+ uploaded_images .append (processed_image )
4339+ else :
4340+ failed_images .append (processed_image .path )
4341+ yield
4342+
4343+ uploaded = []
4344+ for i in range (0 , len (uploaded_images ), 100 ):
4345+ response = AttachFileUrlsUseCase (
4346+ project = self ._project ,
4347+ folder = self ._folder ,
4348+ limit = self .auth_data ["availableImageCount" ],
4349+ backend_service_provider = self ._backend_client ,
4350+ attachments = [image .entity for image in uploaded_images [i : i + 100 ]],
4351+ annotation_status = self ._annotation_status ,
4352+ ).execute ()
4353+
4354+ attachments , duplications = response .data
4355+ uploaded .extend (attachments )
4356+ uploaded = [image ["name" ] for image in uploaded ]
4357+ failed_images = [image .split ("/" )[- 1 ] for image in failed_images ]
4358+
4359+ self ._response .data = uploaded , failed_images , duplications
4360+ return self ._response
0 commit comments