Skip to content

Commit

Permalink
delete file on get only after 3 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
Daggx committed Nov 6, 2024
1 parent 3593d0c commit 19948c3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion edenai_apis/apis/google/google_video_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
AsyncResponseType,
ResponseType,
)
from datetime import datetime, timezone
from dateutil.parser import parse


class GoogleVideoApi(VideoInterface):
Expand All @@ -97,6 +99,14 @@ def google_upload_video(

return gcs_uri

def _is_older_than_3_hours(self, create_time: str) -> bool:
created_at = parse(create_time)
current_time = datetime.now(timezone.utc)
time_diff = current_time - created_at
hours_diff = time_diff.total_seconds() / 3600

return hours_diff > 3

def _check_file_status(self, file_uri: str, api_key: str) -> Dict[str, Any]:
url = f"{file_uri}?key={api_key}"
response = requests.get(url)
Expand Down Expand Up @@ -890,7 +900,9 @@ def video__question_answer_async__get_job_result(
temperature=content["temperature"],
file_data=file_data,
)
self._delete_file(file=file_data["name"], api_key=api_key)
create_time = self._is_older_than_3_hours(file_data["createTime"])
if create_time:
self._delete_file(file=file_data["name"], api_key=api_key)
return AsyncResponseType[QuestionAnswerAsyncDataClass](
original_response=original_response,
standardized_response=QuestionAnswerAsyncDataClass(
Expand Down

0 comments on commit 19948c3

Please sign in to comment.