ugoira: remove the PixivUgoiraFrameData model.
Remove the last remaining uses of the PixivUgoiraFrameData model. As of
32bfb8407, Ugoira frame data is now stored in the MediaMetadata model,
under the `Ugoira:FrameDelays` EXIF field.
The pixiv_ugoira_frame_data table still exists, but it can be removed
after this commit is deployed.
Fixes #5264: Error when replacing with ugoira.
This commit is contained in:
@@ -17,13 +17,12 @@ class MediaAsset < ApplicationRecord
|
||||
|
||||
has_one :post, foreign_key: :md5, primary_key: :md5
|
||||
has_one :media_metadata, dependent: :destroy
|
||||
has_one :pixiv_ugoira_frame_data, class_name: "PixivUgoiraFrameData", foreign_key: :md5, primary_key: :md5
|
||||
has_many :upload_media_assets, dependent: :destroy
|
||||
has_many :uploads, through: :upload_media_assets
|
||||
has_many :uploaders, through: :uploads, class_name: "User", foreign_key: :uploader_id
|
||||
has_many :ai_tags
|
||||
|
||||
delegate :metadata, to: :media_metadata
|
||||
delegate :frame_delays, :metadata, to: :media_metadata
|
||||
delegate :is_non_repeating_animation?, :is_greyscale?, :is_rotated?, :is_ai_generated?, to: :metadata
|
||||
|
||||
scope :public_only, -> { where(is_public: true) }
|
||||
@@ -81,8 +80,8 @@ class MediaAsset < ApplicationRecord
|
||||
|
||||
def open_file
|
||||
file = storage_service.open(file_path)
|
||||
frame_data = media_asset.pixiv_ugoira_frame_data&.data if media_asset.is_ugoira?
|
||||
MediaFile.open(file, frame_data: frame_data, strict: false)
|
||||
frame_delays = media_asset.frame_delays if media_asset.is_ugoira?
|
||||
MediaFile.open(file, frame_delays: frame_delays, strict: false)
|
||||
end
|
||||
|
||||
def convert_file(media_file)
|
||||
@@ -252,7 +251,6 @@ class MediaAsset < ApplicationRecord
|
||||
# XXX should do this in parallel with thumbnail generation.
|
||||
# XXX shouldn't generate thumbnail twice (very slow for ugoira)
|
||||
media_asset.update!(ai_tags: media_file.preview(360, 360).ai_tags)
|
||||
media_asset.update!(pixiv_ugoira_frame_data: PixivUgoiraFrameData.new(data: media_file.frame_data, content_type: "image/jpeg")) if media_asset.is_ugoira?
|
||||
media_asset.update!(media_metadata: MediaMetadata.new(file: media_file))
|
||||
|
||||
media_asset.distribute_files!(media_file)
|
||||
@@ -423,6 +421,6 @@ class MediaAsset < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
%i[post media_metadata pixiv_ugoira_frame_data ai_tags]
|
||||
%i[post media_metadata ai_tags]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,4 +28,8 @@ class MediaMetadata < ApplicationRecord
|
||||
def metadata
|
||||
ExifTool::Metadata.new(self[:metadata])
|
||||
end
|
||||
|
||||
def frame_delays
|
||||
metadata["Ugoira:FrameDelays"].to_a
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PixivUgoiraFrameData < ApplicationRecord
|
||||
belongs_to :post, optional: true, foreign_key: :md5, primary_key: :md5
|
||||
belongs_to :media_asset, foreign_key: :md5, primary_key: :md5
|
||||
|
||||
serialize :data
|
||||
before_validation :normalize_data, on: :create
|
||||
|
||||
def self.available_includes
|
||||
[:post]
|
||||
end
|
||||
|
||||
def self.search(params, current_user)
|
||||
q = search_attributes(params, [:id, :data, :content_type, :post, :md5], current_user: current_user)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def frame_delays
|
||||
data.pluck("delay")
|
||||
end
|
||||
|
||||
def normalize_data
|
||||
return if data.nil?
|
||||
|
||||
if data[0]["delay_msec"]
|
||||
self.data = data.map.with_index do |datum, i|
|
||||
filename = format("%06d.jpg", i)
|
||||
{"delay" => datum["delay_msec"], "file" => filename}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -58,7 +58,6 @@ class Post < ApplicationRecord
|
||||
has_one :media_asset, -> { active }, foreign_key: :md5, primary_key: :md5
|
||||
has_one :media_metadata, through: :media_asset
|
||||
has_one :artist_commentary, :dependent => :destroy
|
||||
has_one :pixiv_ugoira_frame_data, class_name: "PixivUgoiraFrameData", foreign_key: :md5, primary_key: :md5
|
||||
has_one :vote_by_current_user, -> { active.where(user_id: CurrentUser.id) }, class_name: "PostVote" # XXX using current user here is wrong
|
||||
has_many :flags, :class_name => "PostFlag", :dependent => :destroy
|
||||
has_many :appeals, :class_name => "PostAppeal", :dependent => :destroy
|
||||
@@ -1406,7 +1405,7 @@ class Post < ApplicationRecord
|
||||
:last_comment_bumped_at, :last_commented_at, :last_noted_at,
|
||||
:uploader, :approver, :parent,
|
||||
:artist_commentary, :flags, :appeals, :notes, :comments, :children,
|
||||
:approvals, :replacements, :pixiv_ugoira_frame_data],
|
||||
:approvals, :replacements],
|
||||
current_user: current_user
|
||||
)
|
||||
|
||||
@@ -1630,7 +1629,7 @@ class Post < ApplicationRecord
|
||||
# attributes accessible through the ?only= parameter
|
||||
%i[
|
||||
uploader approver flags appeals events parent children notes
|
||||
comments approvals disapprovals replacements pixiv_ugoira_frame_data
|
||||
comments approvals disapprovals replacements
|
||||
artist_commentary media_asset ai_tags
|
||||
]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user