Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sound file playback method to nginx #470

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 55 additions & 7 deletions resources/rootfs/etc/nginx/mikopbx/locations/others.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
location ~ /\.ht {
deny all;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|ico|js|map|woff2)$ {
access_log off;
expires 3d;
}
location ~ /\.ht {
deny all;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|ico|js|map|woff2)$ {
access_log off;
expires 3d;
}

location /pbxcore/api/cdr/v2/playback {
root /storage/usbdisk1/mikopbx;
set_by_lua $session_exists '
local file = "/var/lib/php/session/sess_"..tostring(ngx.var.cookie_PHPSESSID);
local f = io.open(file, "rb")
local result = "fail";
if f then
f:close()
result = "ok"
end
return result;
';
if ( $session_exists = 'fail' ) {
rewrite ^ /pbxcore/api/nchan/auth last;
}
set_by_lua $download '
if (ngx.var.arg_download) then
return ngx.var.arg_download;
end
return 0;
';
set_by_lua $filename '
if (ngx.var.arg_filename) then
return ngx.var.arg_filename;
end
local path = ngx.unescape_uri(ngx.var.arg_view):reverse();
return string.sub(path, 0, string.find(path,"/") - 1):reverse();
';

set_by_lua $result_url '
local path = ngx.unescape_uri(ngx.var.arg_view);
return "/pbxcore/api/cdr/v2/get-record-file"..string.gsub(path,ngx.var.document_root,"");
';
add_header X_TEST "$result_url";

try_files "$result_url" "$result_url";
}

location ^~/pbxcore/api/cdr/v2/get-record-file {
alias /storage/usbdisk1/mikopbx;
if ( $session_exists != 'ok' ) {
rewrite ^ /pbxcore/api/nchan/auth last;
}
if ( $download = '1' ) {
add_header Content-disposition "attachment; filename=$filename";
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ const callDetailRecords = {
<td class="one wide"></td>
<td class="one wide right aligned">
<i class="ui icon play"></i>
<audio preload="metadata" id="audio-player-${record.id}" src="/pbxcore/api/cdr/playback?view=${recordFileUri}"></audio>
<audio preload="metadata" id="audio-player-${record.id}" src="/pbxcore/api/cdr/v2/playback?view=${recordFileUri}"></audio>
</td>
<td class="five wide">
<div class="ui range cdr-player" data-value="${record.id}"></div>
</td>
<td class="one wide"><span class="cdr-duration"></span></td>
<td class="one wide">
<i class="ui icon download" data-value="/pbxcore/api/cdr/playback?view=${recordFileUri}&download=1&filename=${recordFileName}.mp3"></i>
<i class="ui icon download" data-value="/pbxcore/api/cdr/v2/playback?view=${recordFileUri}&download=1&filename=${recordFileName}.mp3"></i>
</td>
<td class="right aligned"><span class="need-update">${record.src_num}</span></td>
<td class="one wide center aligned"><i class="icon exchange"></i></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class sndPlayerOneBtn {
onSuccess(response) {
if (response.message !== undefined) {
_this.html5Audio.getElementsByTagName('source')[0].src
= `/pbxcore/api/cdr/playback?view=${response.message}`;
= `/pbxcore/api/cdr/v2/playback?view=${response.message}`;
_this.html5Audio.pause();
_this.html5Audio.load();
_this.html5Audio.oncanplaythrough = this.cbCanPlayThrough;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const soundFileModify = {
soundFileModify.trashBin.push(soundFileModify.$formObj.form('get value', 'path'));
soundFileModify.$formObj.form('set value', 'path', filename);
soundFileModify.$soundFileName.trigger('change');
sndPlayer.UpdateSource(`/pbxcore/api/cdr/playback?view=${filename}`);
sndPlayer.UpdateSource(`/pbxcore/api/cdr/v2/playback?view=${filename}`);
soundFileModify.$submitButton.removeClass('loading');
soundFileModify.$formObj.removeClass('loading');

Expand Down
2 changes: 1 addition & 1 deletion src/AdminCabinet/Controllers/SoundFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function modifyAction(string $id = ''): void
$form = new SoundFilesEditForm($file);
$this->view->form = $form;
$this->view->category = $file->category;
$this->view->audioPath = empty($file->path) ? '' : "/pbxcore/api/cdr/playback?view={$file->path}";
$this->view->audioPath = empty($file->path) ? '' : "/pbxcore/api/cdr/v2/playback?view={$file->path}";
$this->view->represent = $file->getRepresent();
}

Expand Down
4 changes: 2 additions & 2 deletions src/AdminCabinet/Views/SoundFiles/customTab.volt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% else %}
<i class="ui icon play"></i>
<audio preload="metadata" id="audio-player-{{ record.id }}">
<source src="{{ '/pbxcore/api/cdr/playback?view='~record.path }}"/>
<source src="{{ '/pbxcore/api/cdr/v2/playback?view='~record.path }}"/>
</audio>
{% endif %}
</td>
Expand All @@ -37,7 +37,7 @@
<i class="ui icon download" data-value=""></i>
{% else %}
<i class="ui icon download"
data-value="{{ '/pbxcore/api/cdr/playback?view='~record.path~'&download=1&filename='~record.name~'.mp3' }}"></i>
data-value="{{ '/pbxcore/api/cdr/v2/playback?view='~record.path~'&download=1&filename='~record.name~'.mp3' }}"></i>
{% endif %}

</td>
Expand Down
4 changes: 2 additions & 2 deletions src/AdminCabinet/Views/SoundFiles/mohTab.volt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{% else %}
<i class="ui icon play"></i>
<audio preload="metadata" id="audio-player-{{ record.id }}">
<source src="{{ '/pbxcore/api/cdr/playback?view='~record.path }}"/>
<source src="{{ '/pbxcore/api/cdr/v2/playback?view='~record.path }}"/>
</audio>
{% endif %}
</td>
Expand All @@ -37,7 +37,7 @@
<i class="ui icon download" data-value=""></i>
{% else %}
<i class="ui icon download"
data-value="{{ '/pbxcore/api/cdr/playback?view='~record.path~'&download=1&filename='~record.name~'.mp3' }}"></i>
data-value="{{ '/pbxcore/api/cdr/v2/playback?view='~record.path~'&download=1&filename='~record.name~'.mp3' }}"></i>
{% endif %}

</td>
Expand Down
8 changes: 4 additions & 4 deletions src/PBXCoreREST/Controllers/Cdr/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function callAction($actionName): void

/**
* Прослушивание файла записи с прокруткой.
* /pbxcore/api/cdr/playback MIKO AJAM
* http://172.16.156.212/pbxcore/api/cdr/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/05/11/16/mikopbx-1526043925.13_43T4MdXcpT.mp3
* http://172.16.156.212/pbxcore/api/cdr/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/06/01/17/mikopbx-1527865189.0_qrQeNUixcV.wav
* http://172.16.156.223/pbxcore/api/cdr/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/12/18/09/mikopbx-1545113960.4_gTvBUcLEYh.mp3&download=true&filename=test.mp3
* /pbxcore/api/cdr/v2/playback MIKO AJAM
* http://172.16.156.212/pbxcore/api/cdr/v2/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/05/11/16/mikopbx-1526043925.13_43T4MdXcpT.mp3
* http://172.16.156.212/pbxcore/api/cdr/v2/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/06/01/17/mikopbx-1527865189.0_qrQeNUixcV.wav
* http://172.16.156.223/pbxcore/api/cdr/v2/playback?view=/storage/usbdisk1/mikopbx/voicemailarchive/monitor/2018/12/18/09/mikopbx-1545113960.4_gTvBUcLEYh.mp3&download=true&filename=test.mp3
* Итого имеем следующий набор параметров API:
* * view* - полный путь к файлу записи разговора.
* download - опциональный параметр, скачивать записи или нет
Expand Down