Merge pull request #3134 from evazion/fix-ugoira-replacement
Fix #3133: Allow replacing ugoira posts
This commit is contained in:
@@ -17,11 +17,6 @@ class PostReplacement < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def process!
|
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.
|
# TODO images hosted on s3 need to be deleted from s3 instead of the local filesystem.
|
||||||
if Danbooru.config.use_s3_proxy?(post)
|
if Danbooru.config.use_s3_proxy?(post)
|
||||||
raise NotImplementedError.new("Replacing S3 hosted images not yet supported.")
|
raise NotImplementedError.new("Replacing S3 hosted images not yet supported.")
|
||||||
@@ -45,6 +40,7 @@ class PostReplacement < ActiveRecord::Base
|
|||||||
post.source = upload.source
|
post.source = upload.source
|
||||||
post.tag_string = upload.tag_string
|
post.tag_string = upload.tag_string
|
||||||
rescale_notes
|
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)
|
post.comments.create!({creator: User.system, body: comment_replacement_message, do_not_bump_post: true}, without_protection: true)
|
||||||
ModAction.log(modaction_replacement_message)
|
ModAction.log(modaction_replacement_message)
|
||||||
@@ -67,6 +63,11 @@ class PostReplacement < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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
|
module SearchMethods
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = all
|
q = all
|
||||||
|
|||||||
@@ -153,5 +153,22 @@ class PostReplacementTest < ActiveSupport::TestCase
|
|||||||
assert_not(File.exists?(old_large_file_path))
|
assert_not(File.exists?(old_large_file_path))
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user