about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-06-26 13:02:14 +0200
committerThibaut Girka <thib@sitedethib.com>2020-06-26 13:02:14 +0200
commita01674fb2b4eb210b300b380899d388b0807999a (patch)
treed497e4b75d85ad5e8dd29416775730d29e13f79d /app/models
parent8f4aff9b6fe638b26b9d0bf0fe4151c2cc214d6d (diff)
parent08cf81f8c1b445eba9972214869c376fe6097efb (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models')
-rw-r--r--app/models/media_attachment.rb19
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)