about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-07-14 18:50:19 +0200
committerGitHub <noreply@github.com>2020-07-14 18:50:19 +0200
commita8e84a18f1d84943e8332ff8deba9d91b1cb3efd (patch)
treefc4e77319aea4bd3e7ce96799618f189f9c16775
parent4abe3be321a620641b9a316b168ce754d7438eff (diff)
Fix larger video files not being transcoded (#14306)
Since #14145, the `set_type_and_extension` has been moved from
`before_post_process` to `before_file_post_process`, but while the former
runs before all validations performed by Paperclip, the latter is dependent
on the order validations and hooks are defined.

In our case, this meant video files could be checked against the generic 10MB
limit, causing validation failures, which, internally, make Paperclip skip
post-processing, and thus, transcoding of the video file.

The actual validation would then happen after the type is correctly set, so
the large file would pass validation, but without being transcoded first.

This commit moves the hook definition so that it is run before checking for
the file size.
-rw-r--r--app/models/media_attachment.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 519711401..3f2e0ceb1 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -165,6 +165,9 @@ class MediaAttachment < ApplicationRecord
                     processors: ->(f) { file_processors f },
                     convert_options: GLOBAL_CONVERT_OPTIONS
 
+  before_file_post_process :set_type_and_extension
+  before_file_post_process :check_video_dimensions
+
   validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES
   validates_attachment_size :file, less_than: IMAGE_LIMIT, unless: :larger_media_format?
   validates_attachment_size :file, less_than: VIDEO_LIMIT, if: :larger_media_format?
@@ -257,9 +260,6 @@ class MediaAttachment < ApplicationRecord
 
   after_post_process :set_meta
 
-  before_file_post_process :set_type_and_extension
-  before_file_post_process :check_video_dimensions
-
   class << self
     def supported_mime_types
       IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES