Fix #3815: Adjust notes positions/sizes after post replacement
Bug: Notes weren't rescaled when the 'final_source' field was given
during replacement.
The cause was that the notes were rescaled after the source was saved,
but saving the source clobbered `image_{width,height}_before_last_save`
inside `rescale_notes`.
Regressed in b0c2ddba.
This commit is contained in:
@@ -113,9 +113,10 @@ class UploadService
|
|||||||
post.image_width = upload.image_width
|
post.image_width = upload.image_width
|
||||||
post.image_height = upload.image_height
|
post.image_height = upload.image_height
|
||||||
post.file_size = upload.file_size
|
post.file_size = upload.file_size
|
||||||
post.source = replacement.replacement_url
|
post.source = replacement.final_source.presence || replacement.replacement_url
|
||||||
post.tag_string = upload.tag_string
|
post.tag_string = upload.tag_string
|
||||||
|
|
||||||
|
rescale_notes(post)
|
||||||
update_ugoira_frame_data(post, upload)
|
update_ugoira_frame_data(post, upload)
|
||||||
|
|
||||||
if md5_changed
|
if md5_changed
|
||||||
@@ -124,24 +125,17 @@ class UploadService
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if replacement.final_source.present?
|
|
||||||
post.update(source: replacement.final_source)
|
|
||||||
end
|
|
||||||
|
|
||||||
replacement.save!
|
replacement.save!
|
||||||
post.save!
|
post.save!
|
||||||
|
|
||||||
post.update_iqdb_async
|
post.update_iqdb_async
|
||||||
|
|
||||||
rescale_notes(post)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rescale_notes(post)
|
def rescale_notes(post)
|
||||||
x_scale = post.image_width.to_f / post.image_width_before_last_save.to_f
|
x_scale = post.image_width.to_f / post.image_width_was.to_f
|
||||||
y_scale = post.image_height.to_f / post.image_height_before_last_save.to_f
|
y_scale = post.image_height.to_f / post.image_height_was.to_f
|
||||||
|
|
||||||
post.notes.each do |note|
|
post.notes.each do |note|
|
||||||
note.reload
|
|
||||||
note.rescale!(x_scale, y_scale)
|
note.rescale!(x_scale, y_scale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -956,14 +956,16 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
assert_difference(-> { @note.versions.count }) do
|
assert_difference(-> { @note.versions.count }) do
|
||||||
# replacement image is 80x82, so we're downscaling by 50% (160x164 -> 80x82).
|
# replacement image is 80x82, so we're downscaling by 50% (160x164 -> 80x82).
|
||||||
as_user do
|
as_user do
|
||||||
@post.replace!(replacement_url: "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg")
|
@post.replace!(
|
||||||
|
replacement_url: "https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png",
|
||||||
|
final_source: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
||||||
|
)
|
||||||
end
|
end
|
||||||
@note.reload
|
@note.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal([1024, 768, 1024, 768], [@note.x, @note.y, @note.width, @note.height])
|
assert_equal([40, 41, 40, 41], [@note.x, @note.y, @note.width, @note.height])
|
||||||
rescue Net::OpenTimeout
|
assert_equal("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350", @post.source)
|
||||||
skip "Remote connection to Pixiv failed"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user