diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 9cd52a02b..0917e4d19 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -17,11 +17,6 @@ class PostReplacement < ActiveRecord::Base end def process! - # TODO for ugoiras we need to replace the frame data. - if post.is_ugoira? - raise NotImplementedError.new("Replacing ugoira images not yet supported.") - end - # TODO images hosted on s3 need to be deleted from s3 instead of the local filesystem. if Danbooru.config.use_s3_proxy?(post) raise NotImplementedError.new("Replacing S3 hosted images not yet supported.") @@ -45,6 +40,7 @@ class PostReplacement < ActiveRecord::Base post.source = upload.source post.tag_string = upload.tag_string rescale_notes + update_ugoira_frame_data(upload) post.comments.create!({creator: User.system, body: comment_replacement_message, do_not_bump_post: true}, without_protection: true) ModAction.log(modaction_replacement_message) @@ -67,6 +63,11 @@ class PostReplacement < ActiveRecord::Base end end + def update_ugoira_frame_data(upload) + post.pixiv_ugoira_frame_data.destroy if post.pixiv_ugoira_frame_data.present? + upload.ugoira_service.save_frame_data(post) if post.is_ugoira? + end + module SearchMethods def search(params = {}) q = all diff --git a/test/unit/post_replacement_test.rb b/test/unit/post_replacement_test.rb index 3bba669f6..293de1943 100644 --- a/test/unit/post_replacement_test.rb +++ b/test/unit/post_replacement_test.rb @@ -153,5 +153,22 @@ class PostReplacementTest < ActiveSupport::TestCase assert_not(File.exists?(old_large_file_path)) end end + + context "a post that is replaced by a ugoira" do + should "save the frame data" do + @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") + @post.reload + + assert_equal(80, @post.image_width) + assert_equal(82, @post.image_height) + assert_equal(2804, @post.file_size) + assert_equal("zip", @post.file_ext) + assert_equal("cad1da177ef309bf40a117c17b8eecf5", @post.md5) + assert_equal("cad1da177ef309bf40a117c17b8eecf5", Digest::MD5.file(@post.file_path).hexdigest) + + assert_equal("https://i1.pixiv.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @post.source) + assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @post.pixiv_ugoira_frame_data.data) + end + end end end