Skip to content

Commit

Permalink
Add logging and fixed file existence check in TextToSpeechController (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Codycody31 authored Dec 11, 2023
1 parent 5995fbc commit 8368544
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/app/Http/Controllers/API/TextToSpeechController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,20 @@ 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();

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();

Expand Down

0 comments on commit 8368544

Please sign in to comment.