Skip to content

Commit

Permalink
Need to split the maximum size for tipline content video files. (#2048)
Browse files Browse the repository at this point in the history
We need one maximum size for the Check upload and another one that is actually the maximum size supported by WhatsApp.

Fixes: CV2-5326.
  • Loading branch information
caiosba authored Sep 24, 2024
1 parent 27270fc commit 8779b32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/tipline_content_multimedia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions app/models/concerns/tipline_content_video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 2 additions & 0 deletions config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
3 changes: 2 additions & 1 deletion test/models/tipline_newsletter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 8779b32

Please sign in to comment.