mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-18 14:38:27 +00:00
Change. library loads only needed files. (#2987)
This commit is contained in:
committed by
FusionPBX
parent
38002a8cb4
commit
eb72f3d5ce
@@ -1,3 +1,5 @@
|
||||
function basename(file_name)
|
||||
return (string.match(file_name, "([^/]+)$"))
|
||||
end
|
||||
|
||||
return basename
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user