Additional work on base64 optional storage in the database.

This commit is contained in:
Mark Crane 2015-04-18 19:59:50 +00:00
parent 96f3dc488f
commit 7ba8ca8f84
6 changed files with 40 additions and 12 deletions

View File

@ -36,11 +36,26 @@
end
--check to see if the greeting file exists
if (greeting_id ~= "0") then
if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then
--invalid greeting_id file does not exist
if (storage_type == "base64" or storage_type == "http_cache") then
greeting_invalid = true;
sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]];
status = dbh:query(sql, function(row)
--greeting found
greeting_invalid = false;
end);
if (greeting_invalid) then
greeting_id = "invalid";
end
else
if (greeting_id ~= "0") then
if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then
--invalid greeting_id file does not exist
greeting_id = "invalid";
end
end
end
--validate the greeting_id
@ -77,9 +92,9 @@
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]];
--if (debug["sql"]) then
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
--end
end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");

View File

@ -144,8 +144,10 @@
event:fire();
--if local after email is true then copy the recording file
mkdir(voicemail_dir.."/"..forward_voicemail_id);
copy(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, voicemail_dir.."/"..forward_voicemail_id.."/msg_"..voicemail_message_uuid.."."..vm_message_ext);
if (storage_type ~= "base64") then
mkdir(voicemail_dir.."/"..forward_voicemail_id);
copy(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, voicemail_dir.."/"..forward_voicemail_id.."/msg_"..voicemail_message_uuid.."."..vm_message_ext);
end
--send the email with the voicemail recording attached
send_email(forward_voicemail_id, voicemail_message_uuid);

View File

@ -105,6 +105,10 @@
session:streamFile("silence_stream://1000");
end
end
--remove the voicemail message
if (storage_type == "base64") then
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
end
--to listen to the recording press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then

View File

@ -69,7 +69,7 @@
dofile(scripts_dir.."/resources/functions/base64.lua");
--show the storage type
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
--freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
--base64 encode the file
local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb");
@ -163,6 +163,10 @@
if (session:ready()) then
timeouts = 0;
record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
if (storage_type == "base64") then
--delete the greeting
os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
end
end
else
--invalid greeting_id

View File

@ -81,7 +81,7 @@
pos = string.find(row.voicemail_option_param, " ", 0, true);
action = string.sub( row.voicemail_option_param, 0, pos-1);
data = string.sub( row.voicemail_option_param, pos+1);
--check if the option uses a regex
regex = string.find(row.voicemail_option_digits, "(", 0, true);
if (regex) then
@ -91,14 +91,14 @@
freeswitch.consoleLog("notice", "[voicemail] regex m:~"..digits.."~"..row.voicemail_option_digits.."~$1\n");
freeswitch.consoleLog("notice", "[voicemail] result: "..result.."\n");
end
--replace the $1 and the domain name
data = data:gsub("$1", result);
data = data:gsub("${domain_name}", domain_name);
end --if regex
end --if menu-exex-app
end --if regex match
--execute
if (action) then
if (string.len(action) > 0) then
@ -128,7 +128,6 @@
end
end
end
end
end
end

View File

@ -97,6 +97,10 @@
if (session:ready()) then
timeouts = 0;
record_menu("name", voicemail_dir.."/"..voicemail_id.."/recorded_name.wav");
if (storage_type == "base64") then
--delete the greeting
os.remove(voicemail_dir.."/"..voicemail_id.."/recorded_name.wav");
end
end
end
end