diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/media_attachment.rb | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index f789bdc55..3fe35ceaa 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -194,15 +194,17 @@ class MediaAttachment < ApplicationRecord x, y = (point.is_a?(Enumerable) ? point : point.split(',')).map(&:to_f) - meta = file.instance_read(:meta) || {} + meta = (file.instance_read(:meta) || {}).with_indifferent_access.slice(:focus, :original, :small) meta['focus'] = { 'x' => x, 'y' => y } file.instance_write(:meta, meta) end def focus - x = file.meta['focus']['x'] - y = file.meta['focus']['y'] + x = file.meta&.dig('focus', 'x') + y = file.meta&.dig('focus', 'y') + + return if x.nil? || y.nil? "#{x},#{y}" end @@ -219,12 +221,11 @@ class MediaAttachment < ApplicationRecord before_create :prepare_description, unless: :local? before_create :set_shortcode before_create :set_processing + before_create :set_meta before_post_process :set_type_and_extension before_post_process :check_video_dimensions - before_save :set_meta - class << self def supported_mime_types IMAGE_MIME_TYPES + VIDEO_MIME_TYPES + AUDIO_MIME_TYPES @@ -306,15 +307,11 @@ class MediaAttachment < ApplicationRecord end def set_meta - meta = populate_meta - - return if meta == {} - - file.instance_write :meta, meta + file.instance_write :meta, populate_meta end def populate_meta - meta = file.instance_read(:meta) || {} + meta = (file.instance_read(:meta) || {}).with_indifferent_access.slice(:focus, :original, :small) file.queued_for_write.each do |style, file| meta[style] = style == :small || image? ? image_geometry(file) : video_metadata(file) |