From 83685442ea6eba3110611b69dc3b421744d1ff7e Mon Sep 17 00:00:00 2001 From: Insidious Fiddler Date: Mon, 11 Dec 2023 13:06:25 -0500 Subject: [PATCH] Add logging and fixed file existence check in TextToSpeechController (#51) --- src/app/Http/Controllers/API/TextToSpeechController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/Http/Controllers/API/TextToSpeechController.php b/src/app/Http/Controllers/API/TextToSpeechController.php index 33faddf..13bbdb2 100644 --- a/src/app/Http/Controllers/API/TextToSpeechController.php +++ b/src/app/Http/Controllers/API/TextToSpeechController.php @@ -203,6 +203,7 @@ public function generate(Request $request): JsonResponse // Write the file to the server storage Storage::disk()->put("atis/$file_id/$name", $output); $file_url = Storage::url("atis/$file_id/$name"); + Log::info("File URL: $file_url"); if (!$file_url) { // Delete the database entry $atis_file->delete(); @@ -210,8 +211,12 @@ public function generate(Request $request): JsonResponse return Helpers::response('Could not generate ATIS audio file.', null, 422, 'error'); } - // Validate that the file exists - if (!Storage::disk()->exists("atis/$file_id/$name")) { + // Make curl call and see if the file exists + $ch = curl_init($file_url); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_exec($ch); + $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($retcode != 200) { // Delete the database entry $atis_file->delete();