forked from e621ng/e621ng
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:
parent
d2f92b7aa7
commit
8408c0bf80
@ -113,9 +113,10 @@ class UploadService
|
||||
post.image_width = upload.image_width
|
||||
post.image_height = upload.image_height
|
||||
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
|
||||
|
||||
rescale_notes(post)
|
||||
update_ugoira_frame_data(post, upload)
|
||||
|
||||
if md5_changed
|
||||
@ -124,24 +125,17 @@ class UploadService
|
||||
end
|
||||
end
|
||||
|
||||
if replacement.final_source.present?
|
||||
post.update(source: replacement.final_source)
|
||||
end
|
||||
|
||||
replacement.save!
|
||||
post.save!
|
||||
|
||||
post.update_iqdb_async
|
||||
|
||||
rescale_notes(post)
|
||||
end
|
||||
|
||||
def rescale_notes(post)
|
||||
x_scale = post.image_width.to_f / post.image_width_before_last_save.to_f
|
||||
y_scale = post.image_height.to_f / post.image_height_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_was.to_f
|
||||
|
||||
post.notes.each do |note|
|
||||
note.reload
|
||||
note.rescale!(x_scale, y_scale)
|
||||
end
|
||||
end
|
||||
|
@ -956,14 +956,16 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
assert_difference(-> { @note.versions.count }) do
|
||||
# replacement image is 80x82, so we're downscaling by 50% (160x164 -> 80x82).
|
||||
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
|
||||
@note.reload
|
||||
end
|
||||
|
||||
assert_equal([1024, 768, 1024, 768], [@note.x, @note.y, @note.width, @note.height])
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to Pixiv failed"
|
||||
assert_equal([40, 41, 40, 41], [@note.x, @note.y, @note.width, @note.height])
|
||||
assert_equal("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350", @post.source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user