diff --git a/app/logical/source/extractor/fanbox.rb b/app/logical/source/extractor/fanbox.rb index 362647798..9cafcfc38 100644 --- a/app/logical/source/extractor/fanbox.rb +++ b/app/logical/source/extractor/fanbox.rb @@ -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 diff --git a/test/unit/sources/fanbox_test.rb b/test/unit/sources/fanbox_test.rb index 057223704..50800cc15 100644 --- a/test/unit/sources/fanbox_test.rb +++ b/test/unit/sources/fanbox_test.rb @@ -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"