Fix #5238: Trying to upload a pixiv direct image url that got trumped by a revision redirects to the new post if it's uploaded.

Bug: When uploading a direct Pixiv image URL, we ignored it in favor of the
image URL returned by the Pixiv API. This meant if you tried to upload the
original version of a revised image, we would get the revised version instead.

Fix: When given a direct Pixiv image URL, use it as-is if it's a full
image URL. If it's a sample image URL, ignore it in favor of the full image
URL as returned by the API, unless the post is deleted and the API data
is unavailable.
This commit is contained in:
evazion
2022-08-24 15:32:57 -05:00
parent f46134e87f
commit bf3ee9cfb8
3 changed files with 43 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
module Source
class URL::Pixiv < Source::URL
attr_reader :work_id, :page, :username, :user_id
attr_reader :work_id, :image_type, :page, :username, :user_id
def self.match?(url)
return false if Source::URL::Fanbox.match?(url) || Source::URL::PixivSketch.match?(url) || Source::URL::Booth.match?(url)
@@ -27,7 +27,8 @@ module Source
# but not:
#
# https://i.pximg.net/novel-cover-original/img/2019/01/14/01/15/05/10617324_d84daae89092d96bbe66efafec136e42.jpg
in *, ("img-original" | "img-master" | "img-zip-ugoira" | "img-inf" | "custom-thumb"), "img", year, month, day, hour, min, sec, file if image_url?
in *, ("img-original" | "img-master" | "img-zip-ugoira" | "img-inf" | "custom-thumb") => type, "img", year, month, day, hour, min, sec, file if image_url?
@image_type = type
parse_filename
# http://img18.pixiv.net/img/evazion/14901720.png
@@ -128,6 +129,10 @@ module Source
host.in?(["i.pximg.net", "i-f.pximg.net", "tc-pximg01.techorus-cdn.com"]) || host.match?(/\A(i\d+|img\d+)\.pixiv\.net\z/)
end
def full_image_url?
image_type.in?(%w[img-original img-zip-ugoira])
end
def is_ugoira?
@ugoira.present?
end