From 7d641711fc316ebdf0c9a0476081f46db760e75d Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 12 Sep 2022 16:53:12 -0600 Subject: [PATCH] Get the mime type to set vm_message_ext --- .../resources/functions/listen_to_recording.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/scripts/resources/scripts/app/voicemail/resources/functions/listen_to_recording.lua b/app/scripts/resources/scripts/app/voicemail/resources/functions/listen_to_recording.lua index 875452ec26..e1ace902c6 100644 --- a/app/scripts/resources/scripts/app/voicemail/resources/functions/listen_to_recording.lua +++ b/app/scripts/resources/scripts/app/voicemail/resources/functions/listen_to_recording.lua @@ -90,7 +90,7 @@ --set the voicemail message path mkdir(voicemail_dir.."/"..voicemail_id); message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext; - message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext; + message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid; --save the recording to the file system if (string.len(row["message_intro_base64"]) > 32) then @@ -105,6 +105,21 @@ --write decoded string to file assert(file.write_base64(message_location, row["message_base64"])); end + + --get the file type + command = "file -b --mime-type "..message_location; + local handle = io.popen(command); + local mime_type = trim(handle:read("*a")); + handle:close(); + if (mime_type == 'audio/x-wav') then + vm_message_ext = 'wav'; + end + if (mime_type == 'audio/mpeg') then + vm_message_ext = 'mp3'; + end + + --rename the file + os.execute('mv '..message_location..' '..message_location..'.'..vm_message_ext); end); dbh:release() elseif (storage_type == "http_cache") then