From 8779b3279cc4510f46279409ec0b3ddf3c1e2052 Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Tue, 24 Sep 2024 13:14:54 -0300 Subject: [PATCH] Need to split the maximum size for tipline content video files. (#2048) We need one maximum size for the Check upload and another one that is actually the maximum size supported by WhatsApp. Fixes: CV2-5326. --- app/models/concerns/tipline_content_multimedia.rb | 2 +- app/models/concerns/tipline_content_video.rb | 13 +++++++++---- config/config.yml.example | 2 ++ test/models/tipline_newsletter_test.rb | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/tipline_content_multimedia.rb b/app/models/concerns/tipline_content_multimedia.rb index 210ef27ea..94fe7af85 100644 --- a/app/models/concerns/tipline_content_multimedia.rb +++ b/app/models/concerns/tipline_content_multimedia.rb @@ -51,7 +51,7 @@ def convert_header_file_audio_or_video(type) output_path = File.join(Rails.root, 'tmp', "#{content_name}-#{type}-output-#{self.id}-#{now}.mp4") video = FFMPEG::Movie.new(input.path) video.transcode(output_path, options) - raise TiplineContentMultimedia::ConvertedFileTooLarge.new('Converted file for tipline content is too large') if (File.size(output_path).to_f / 1024000.0) > self.header_file_video_max_size + raise TiplineContentMultimedia::ConvertedFileTooLarge.new('Converted file for tipline content is too large') if (File.size(output_path).to_f / 1024000.0) > self.header_file_video_max_size_whatsapp path = "#{content_name}/video/#{content_name}-#{type}-#{self.id}-#{now}" CheckS3.write(path, 'video/mp4', File.read(output_path)) url = CheckS3.public_url(path) diff --git a/app/models/concerns/tipline_content_video.rb b/app/models/concerns/tipline_content_video.rb index 668247151..9b67c601d 100644 --- a/app/models/concerns/tipline_content_video.rb +++ b/app/models/concerns/tipline_content_video.rb @@ -3,13 +3,18 @@ module TiplineContentVideo extend ActiveSupport::Concern - # MP4 less than 10 MB (WhatsApp supports 16 MB, let's be safe) - def header_file_video_max_size - 10 + # Max size that WhatsApp supports + def header_file_video_max_size_whatsapp + CheckConfig.get(:header_file_video_max_size_whatsapp, 16, :integer) + end + + # Max size for Check (we need to convert it to H.264, so let's be safe and use a value less than what WhatsApp supports) + def header_file_video_max_size_check + CheckConfig.get(:header_file_video_max_size_check, 10, :integer) end def validate_header_file_video - self.validate_header_file(self.header_file_video_max_size, ['mp4'], 'errors.messages.video_too_large') + self.validate_header_file(self.header_file_video_max_size_check, ['mp4'], 'errors.messages.video_too_large') end def should_convert_header_video? diff --git a/config/config.yml.example b/config/config.yml.example index a94a6131e..506fe4156 100644 --- a/config/config.yml.example +++ b/config/config.yml.example @@ -277,6 +277,8 @@ development: &default api_rate_limit: 100 export_csv_maximum_number_of_results: 10000 export_csv_expire: 604800 # Seconds: Default is 7 days + header_file_video_max_size_whatsapp: 16 # Megabytes + header_file_video_max_size_check: 10 # Megabytes, should be less than WhatsApp limit # Session # diff --git a/test/models/tipline_newsletter_test.rb b/test/models/tipline_newsletter_test.rb index 4f9dfcd9c..a209216c7 100644 --- a/test/models/tipline_newsletter_test.rb +++ b/test/models/tipline_newsletter_test.rb @@ -484,7 +484,8 @@ def teardown # This test file is 300 KB, but 1.6 MB after converting WebMock.stub_request(:get, /:9000/).to_return(body: File.read(File.join(Rails.root, 'test', 'data', 'h265-video.mp4'))) TiplineNewsletter.any_instance.stubs(:new_file_uploaded?).returns(true) - TiplineNewsletter.any_instance.stubs(:header_file_video_max_size).returns(1) # Maximum 1 MB + TiplineNewsletter.any_instance.stubs(:header_file_video_max_size_check).returns(2) # Maximum 2 MB + TiplineNewsletter.any_instance.stubs(:header_file_video_max_size_whatsapp).returns(1) # Maximum 1 MB CheckSentry.stubs(:notify).once Sidekiq::Testing.inline! do create_tipline_newsletter header_type: 'video', header_file: 'h265-video.mp4'