Skip to content

Commit

Permalink
add support for wav files (#1452)
Browse files Browse the repository at this point in the history
* add support for wav files
  • Loading branch information
dmitry-sinina authored Mar 28, 2024
1 parent 9e3580b commit f051038
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/admin/cdr/cdrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def scoped_collection
raise ActiveRecord::RecordNotFound if file.blank?

response.headers['X-Accel-Redirect'] = file
response.headers['Content-Type'] = 'audio/mpeg'
response.headers['Content-Type'] = resource.call_record_ct
head 200
end

Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/rest/admin/cdr/cdrs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Api::Rest::Admin::Cdr::CdrsController < Api::Rest::Admin::BaseController
def recording
if @cdr.has_recording?
response.headers['X-Accel-Redirect'] = @cdr.call_record_filename
response.headers['Content-Type'] = @cdr.call_record_ct
render body: nil
else
head 404
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/rest/customer/v1/cdrs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::Rest::Customer::V1::CdrsController < Api::Rest::Customer::V1::BaseCon
def rec
if current_customer.allow_listen_recording && @cdr.has_recording?
response.headers['X-Accel-Redirect'] = @cdr.call_record_filename
response.headers['Content-Type'] = 'audio/mpeg'
response.headers['Content-Type'] = @cdr.call_record_ct
render body: nil
else
head 404
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::Rest::Customer::V1::IncomingCdrsController < Api::Rest::Customer::V1:
def rec
if current_customer.allow_listen_recording && @cdr.has_recording?
response.headers['X-Accel-Redirect'] = @cdr.call_record_filename
response.headers['Content-Type'] = 'audio/mpeg'
response.headers['Content-Type'] = @cdr.call_record_ct
render body: nil
else
head 404
Expand Down
7 changes: 6 additions & 1 deletion app/models/cdr/cdr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,12 @@ def has_recording?
end

def call_record_filename
"/record/#{local_tag}.mp3" if has_recording?
fmt = YetiConfig.rec_format == 'wav' ? 'wav' : 'mp3'
"/record/#{local_tag}.#{fmt}" if has_recording?
end

def call_record_ct
YetiConfig.rec_format == 'wav' ? 'audio/wav' : 'audio/mpeg'
end

def attempts
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def self.setting_files(config_root, _env)
required(:token_lifetime).maybe(:int?)
end

optional(:rec_format).value(Dry::Types['string'].enum('wav', 'mp3'))

required(:cdr_export).schema do
required(:dir_path).filled(:string)
required(:delete_url).filled(:string)
Expand Down
1 change: 1 addition & 0 deletions spec/requests/api/rest/admin/cdr/cdrs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
expect(response.status).to eq 200
expect(response.body).to be_blank
expect(response.headers['X-Accel-Redirect']).to eq "/record/#{cdr.local_tag}.mp3"
expect(response.headers['Content-Type']).to eq 'audio/mpeg'
end

context 'when audio not recorded' do
Expand Down
1 change: 1 addition & 0 deletions spec/requests/api/rest/customer/v1/cdrs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
expect(response.status).to eq 200
expect(response.body).to be_blank
expect(response.headers['X-Accel-Redirect']).to eq cdr.call_record_filename
expect(response.headers['Content-Type']).to eq cdr.call_record_ct
end

context 'when cdr audio not recorded' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@
expect(response.status).to eq 200
expect(response.body).to be_blank
expect(response.headers['X-Accel-Redirect']).to eq cdr.call_record_filename
expect(response.headers['Content-Type']).to eq cdr.call_record_ct
end

context 'when cdr audio not recorded' do
Expand Down

0 comments on commit f051038

Please sign in to comment.