Change. library loads only needed files. (#2987)

This commit is contained in:
Alexey Melnichuk
2018-02-11 18:56:01 +03:00
committed by FusionPBX
parent 38002a8cb4
commit eb72f3d5ce
6 changed files with 41 additions and 28 deletions

View File

@@ -31,16 +31,13 @@
--include config.lua
require "resources.functions.config";
--create logger object
log = require "resources.functions.log".call_flow
--additional includes
local presence_in = require "resources.functions.presence_in"
local Database = require "resources.functions.database"
local Settings = require "resources.functions.lazy_settings"
file = require "resources.functions.file"
log = require "resources.functions.log".call_flow
require "resources.functions.basename"
require "resources.functions.is_absolute_path"
require "resources.functions.find_file"
require "resources.functions.play_file"
local play_file = require "resources.functions.play_file"
--include json library
local json
@@ -52,19 +49,16 @@
local dbh = Database.new('system');
--get the variables
if (session:ready()) then
domain_name = session:getVariable("domain_name");
domain_uuid = session:getVariable("domain_uuid");
call_flow_uuid = session:getVariable("call_flow_uuid");
sounds_dir = session:getVariable("sounds_dir");
feature_code = session:getVariable("feature_code");
end
if not session:ready() then return end
--set the sounds path for the language, dialect and voice
if (session:ready()) then
local default_language = session:getVariable("default_language") or 'en';
local default_dialect = session:getVariable("default_dialect") or 'us';
local default_voice = session:getVariable("default_voice") or 'callie';
local domain_name = session:getVariable("domain_name");
local domain_uuid = session:getVariable("domain_uuid");
local call_flow_uuid = session:getVariable("call_flow_uuid");
local feature_code = session:getVariable("feature_code");
if not call_flow_uuid then
log.warning('Can not get call flow uuid')
return
end
--get the call flow details
@@ -179,6 +173,7 @@
if (session:ready()) then
session:execute(app, data);
end
--timeout application
--if (not session:answered()) then
-- session:execute(ring_group_timeout_app, ring_group_timeout_data);

View File

@@ -1,3 +1,5 @@
function basename(file_name)
return (string.match(file_name, "([^/]+)$"))
end
return basename

View File

@@ -2,7 +2,7 @@
pcall(require, "resources.functions.base64")
-- load logger for file library
local log = require "resources.functions.log".file
local log = log or require "resources.functions.log"[app_name or 'file']
local base64 = base64

View File

@@ -1,6 +1,11 @@
local log = log or require "resources.functions.log"[app_name or 'find_file']
local file = require "resources.functions.file"
local Settings = require "resources.functions.lazy_settings"
local basename = require "resources.functions.basename"
local is_absolute_path = require "resources.functions.is_absolute_path"
function find_file(dbh, domain_name, domain_uuid, file_name)
-- if we specify e.g. full path
if (is_absolute_path(file_name) and file.exists(file_name)) then
log.debugf('found file `%s` in file system', file_name)
@@ -43,14 +48,16 @@ function find_file(dbh, domain_name, domain_uuid, file_name)
if not found then
local sounds_dir
if session then
-- Implemented based on stream.lua. But seems it never works.
-- because if we have file like `digits/1.wav` but full_path is `sounds_dir/digits/XXXX/1.wav`
sounds_dir = session:getVariable("sounds_dir")
local default_language = session:getVariable("default_language") or 'en'
local default_dialect = session:getVariable("default_dialect") or 'us'
local default_voice = session:getVariable("default_voice") or 'callie'
if session:ready() then
-- Implemented based on stream.lua. But seems it never works.
-- because if we have file like `digits/1.wav` but full_path is `sounds_dir/digits/XXXX/1.wav`
sounds_dir = session:getVariable("sounds_dir")
local default_language = session:getVariable("default_language") or 'en'
local default_dialect = session:getVariable("default_dialect") or 'us'
local default_voice = session:getVariable("default_voice") or 'callie'
sounds_dir = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice
sounds_dir = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice
end
else
--! @todo implement for not session call.
end
@@ -70,3 +77,5 @@ function find_file(dbh, domain_name, domain_uuid, file_name)
return file_name, is_base64
end
return find_file

View File

@@ -1,3 +1,5 @@
function is_absolute_path(file_name)
return string.sub(file_name, 1, 1) == '/' or string.sub(file_name, 2, 1) == ':'
end
return is_absolute_path

View File

@@ -1,3 +1,6 @@
local log = log or require "resources.functions.log"[app_name or 'play_file']
local find_file = require "resources.functions.find_file"
function play_file(dbh, domain_name, domain_uuid, file_name)
local full_path, is_base64 = find_file(dbh, domain_name, domain_uuid, file_name)
if not full_path then
@@ -8,3 +11,5 @@ function play_file(dbh, domain_name, domain_uuid, file_name)
end
session:execute("playback", full_path);
end
return play_file