Fix #5082: NoMethodError when searching an old-style dead fanbox url in artist urls.
This API call:
# profile: https://www.pixiv.net/fanbox/creator/40684196
curl -H "Origin: https://fanbox.cc" "https://api.fanbox.cc/creator.get?userId=40684196"
returns `{ "body": nil }` when the artist is deleted. We didn't expect `body` to be nil.
Also fix it so that `profile_url` returns the `https://www.pixiv.net/fanbox/creator/40684196`
URL if we can't get the `https://<username>.fanbox.cc` URL, usually because the API call failed
because the artist is deleted.
This commit is contained in:
@@ -35,17 +35,19 @@ module Source
|
||||
end
|
||||
|
||||
def profile_url
|
||||
return if artist_name.blank?
|
||||
|
||||
"https://#{artist_name}.fanbox.cc"
|
||||
if artist_name.present?
|
||||
"https://#{artist_name}.fanbox.cc"
|
||||
elsif artist_id_from_url.present?
|
||||
"https://www.pixiv.net/fanbox/creator/#{artist_id_from_url}"
|
||||
end
|
||||
end
|
||||
|
||||
def artist_name
|
||||
artist_name_from_url || api_response["creatorId"] || artist_api_response["creatorId"]
|
||||
artist_name_from_url || api_response["creatorId"] || artist_api_response.dig("body", "creatorId")
|
||||
end
|
||||
|
||||
def display_name
|
||||
api_response.dig("user", "name") || artist_api_response.dig("user", "name")
|
||||
api_response.dig("user", "name") || artist_api_response.dig("body", "user", "name")
|
||||
end
|
||||
|
||||
def other_names
|
||||
@@ -110,10 +112,11 @@ module Source
|
||||
def artist_api_response
|
||||
# Needed to fetch artist from cover pages
|
||||
return {} if artist_id_from_url.blank?
|
||||
|
||||
resp = client.get("https://api.fanbox.cc/creator.get?userId=#{artist_id_from_url}")
|
||||
JSON.parse(resp)["body"]
|
||||
rescue JSON::ParserError
|
||||
{}
|
||||
return {} if resp.status != 200
|
||||
|
||||
resp.parse
|
||||
end
|
||||
|
||||
def client
|
||||
|
||||
@@ -135,6 +135,15 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "A deleted /fanbox/creator/:id profile url" do
|
||||
should "not raise an exception" do
|
||||
source = Source::Extractor.find("https://www.pixiv.net/fanbox/creator/40684196")
|
||||
|
||||
assert_equal("https://www.pixiv.net/fanbox/creator/40684196", source.profile_url)
|
||||
assert_nothing_raised { source.to_h }
|
||||
end
|
||||
end
|
||||
|
||||
context "generating page urls" do
|
||||
should "convert cover images to the profile url" do
|
||||
cover = "https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg"
|
||||
|
||||
Reference in New Issue
Block a user