ugoira: store frame delays in MediaMetadata model.
Store Ugoira frame delays in the MediaMetadata model as a fake EXIF field instead of in the PixivUgoiraFrameData model. This way we can get rid of the PixivUgoiraFrameData model completely. This is a step towards fixing #5264.
This commit is contained in:
@@ -22,6 +22,10 @@ class MediaFile::Ugoira < MediaFile
|
||||
preview_frame.close
|
||||
end
|
||||
|
||||
def metadata
|
||||
super.merge("Ugoira:FrameDelays" => frame_delays)
|
||||
end
|
||||
|
||||
def dimensions
|
||||
preview_frame.dimensions
|
||||
end
|
||||
|
||||
@@ -56,6 +56,7 @@ class Post < ApplicationRecord
|
||||
belongs_to :uploader, :class_name => "User", :counter_cache => "post_upload_count"
|
||||
belongs_to :parent, class_name: "Post", optional: true
|
||||
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
|
||||
|
||||
21
script/fixes/120_migrate_ugoira_frame_data.rb
Executable file
21
script/fixes/120_migrate_ugoira_frame_data.rb
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative "base"
|
||||
|
||||
with_confirmation do
|
||||
MediaMetadata.joins(:media_asset).where(media_asset: { file_ext: "zip" }).find_each do |meta|
|
||||
frame_data = PixivUgoiraFrameData.find_by(md5: meta.media_asset.md5)
|
||||
|
||||
if frame_data.nil?
|
||||
puts "Missing frame data: #{meta.media_asset.md5}"
|
||||
next
|
||||
elsif meta.metadata["Ugoira:FrameDelays"] == frame_data.frame_delays
|
||||
next
|
||||
end
|
||||
|
||||
json = meta.metadata.as_json.merge("Ugoira:FrameDelays" => frame_data.frame_delays)
|
||||
meta.update!(metadata: json) if ENV.fetch("FIX", "false").truthy?
|
||||
|
||||
puts meta.as_json
|
||||
end
|
||||
end
|
||||
@@ -129,6 +129,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @post.source)
|
||||
assert_equal([{"delay" => 125, "file" => "000000.jpg"}, {"delay" => 125, "file" => "000001.jpg"}], @post.pixiv_ugoira_frame_data.data)
|
||||
assert_equal([125, 125], @post.media_asset.metadata["Ugoira:FrameDelays"])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -287,6 +287,14 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
context "uploading a ugoira" do
|
||||
should "work" do
|
||||
upload = assert_successful_upload("https://www.pixiv.net/en/artworks/45982180", user: @user)
|
||||
|
||||
assert_equal([60] * 70, upload.media_assets.first.metadata["Ugoira:FrameDelays"])
|
||||
end
|
||||
end
|
||||
|
||||
context "uploading a file from a source" do
|
||||
should_upload_successfully("https://www.artstation.com/artwork/04XA4")
|
||||
should_upload_successfully("https://dantewontdie.artstation.com/projects/YZK5q")
|
||||
|
||||
Reference in New Issue
Block a user