Fix various issues around OpenGraph representation of media (#14133)
- Fix audio attachments not being represented in OpenGraph tags - Fix audio being represented as "1 image" in OpenGraph descriptions - Fix video metadata being overwritten by paperclip-av-transcoder - Fix embedded player not using Mastodon's UI - Fix audio/video progress bars not moving smoothly - Fix audio/video buffered bars not displaying correctly
This commit is contained in:
parent
e9ff61ca07
commit
662a49dc3f
12 changed files with 117 additions and 41 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue