From 6bb1ef368ee906834fc8c7e25b48be3f89826b06 Mon Sep 17 00:00:00 2001 From: PascalSun Date: Wed, 24 Jul 2024 18:18:28 +0800 Subject: [PATCH] update the return for video --- API/hardware/views.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/API/hardware/views.py b/API/hardware/views.py index a63a41ad..d6bc09d1 100644 --- a/API/hardware/views.py +++ b/API/hardware/views.py @@ -272,7 +272,7 @@ def client_audio(request, audio_id): ) if (settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3) or ( - settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API + settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API ): # we will grab it from the s3 and return it @@ -280,7 +280,7 @@ def client_audio(request, audio_id): # construct the key and then create the pre-signed url s3_key = f"Listener/audio/{audio_obj.uid}/{audio_obj.audio_file}" local_file = ( - settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file + settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file ) # check if the file exists locally if not local_file.exists(): @@ -301,7 +301,7 @@ def client_audio(request, audio_id): return response audio_file = ( - settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file + settings.CLIENT_MEDIA_ROOT / "audio" / audio_obj.uid / audio_obj.audio_file ) with open(audio_file, "rb") as f: response = HttpResponse(f.read(), content_type="audio/mpeg") @@ -316,13 +316,13 @@ def ai_audio(request, audio_id): return HttpResponse("No audio data found.", content_type="text/plain") if (settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3) or ( - settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API + settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API ): # we will grab it from the s3 and return it s3_client = settings.BOTO3_SESSION.client("s3") s3_key = f"Responder/tts/{res_audio_obj.text2speech_file.split('/')[-1]}" local_file = ( - settings.AI_MEDIA_ROOT / res_audio_obj.text2speech_file.split("/")[-1] + settings.AI_MEDIA_ROOT / res_audio_obj.text2speech_file.split("/")[-1] ) # check if the file exists locally if not local_file.exists(): @@ -378,11 +378,11 @@ def client_video(request, conversation_id): video_paths = [] for video in videos: video_path = ( - settings.CLIENT_MEDIA_ROOT / "videos" / video.uid / video.video_file + settings.CLIENT_MEDIA_ROOT / "videos" / video.uid / video.video_file ) if not video_path.exists() and ( - settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3 - or settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API + settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_S3 + or settings.STORAGE_SOLUTION == settings.STORAGE_SOLUTION_API ): video_path.parent.mkdir(parents=True, exist_ok=True) s3_client = settings.BOTO3_SESSION.client("s3") @@ -396,16 +396,11 @@ def client_video(request, conversation_id): except Exception as e: logger.error(e) # response with the HttpResponse - response = HttpResponse( - str(e), - content_type="text/plain", - status=status.HTTP_500_INTERNAL_SERVER_ERROR, - ) - return + continue video_paths.append(video_path.as_posix()) output_path = ( - settings.CLIENT_MEDIA_ROOT / "conversations" / f"{conversation.id}.mp4" + settings.CLIENT_MEDIA_ROOT / "conversations" / f"{conversation.id}.mp4" ) output_path.parent.mkdir(parents=True, exist_ok=True)