fanbox: don't raise error on age-restricted posts.
Prevent age-restricted fanbox posts from raising errors when source data is fetched. This prevents error messages from being shown to users when switching to the edit tab on a post. This will cause uploads of age-restricted posts to fail with an unrelated error because we either can't find the image url (if we were given only the html page) or we can't download the image (because we're not logged in to Fanbox).
This commit is contained in:
@@ -105,11 +105,7 @@ module Sources
|
||||
end
|
||||
|
||||
def display_name
|
||||
if api_response.present?
|
||||
api_response["user"]["name"]
|
||||
elsif artist_api_response.present?
|
||||
artist_api_response["user"]["name"]
|
||||
end
|
||||
api_response.dig("user", "name") || artist_api_response.dig("user", "name")
|
||||
end
|
||||
|
||||
def other_names
|
||||
@@ -125,8 +121,9 @@ module Sources
|
||||
end
|
||||
|
||||
def artist_commentary_desc
|
||||
return if api_response.blank?
|
||||
body = api_response["body"]
|
||||
return if body.blank?
|
||||
|
||||
if body["text"].present?
|
||||
body["text"]
|
||||
elsif body["blocks"].present?
|
||||
@@ -160,11 +157,12 @@ module Sources
|
||||
return {} if illust_id.blank?
|
||||
resp = client.get("https://api.fanbox.cc/post.info?postId=#{illust_id}")
|
||||
json_response = JSON.parse(resp)["body"]
|
||||
if json_response["restrictedFor"] == 2 && json_response["body"].blank?
|
||||
# Pixiv Fanbox login is protected by Google Recaptcha, so it's not possible for us to extract anything from them (save for the title).
|
||||
# Other projects like PixivUtils ask the user to periodically extract cookies from the browser, but this is not feasible for Danbooru.
|
||||
raise Sources::Error, "Age-restricted posts from Pixiv Fanbox are not supported."
|
||||
end
|
||||
|
||||
# Pixiv Fanbox login is protected by Google Recaptcha, so it's not
|
||||
# possible for us to extract anything from them (save for the title).
|
||||
# Other projects like PixivUtils ask the user to periodically extract
|
||||
# cookies from the browser, but this is not feasible for Danbooru.
|
||||
return {} if json_response["restrictedFor"] == 2 && json_response["body"].blank?
|
||||
|
||||
json_response
|
||||
rescue JSON::ParserError
|
||||
@@ -181,7 +179,7 @@ module Sources
|
||||
end
|
||||
|
||||
def client
|
||||
Danbooru::Http.headers(Origin: "https://fanbox.cc").cache(1.minute)
|
||||
@client ||= http.headers(Origin: "https://fanbox.cc").cache(1.minute)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -371,6 +371,9 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
should_upload_successfully("https://art.ngfiles.com/images/1254000/1254722_natthelich_pandora.jpg")
|
||||
should_upload_successfully("https://art.ngfiles.com/comments/57000/iu_57615_7115981.jpg")
|
||||
should_upload_successfully("https://www.newgrounds.com/art/view/puddbytes/costanza-at-bat")
|
||||
|
||||
should_upload_successfully("https://www.fanbox.cc/@tsukiori/posts/1080657")
|
||||
should_upload_successfully("https://downloads.fanbox.cc/images/post/1080657/SaakPC251KafLL6jIo1WPPmr.png")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,6 +90,15 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "an age-restricted fanbox post" do
|
||||
should "not raise an error" do
|
||||
@source = Sources::Strategies.find("https://mfr.fanbox.cc/posts/1306390")
|
||||
|
||||
assert_nothing_raised { @source.to_h }
|
||||
assert_equal("mfr", @source.artist_name)
|
||||
end
|
||||
end
|
||||
|
||||
context "A link in the old format" do
|
||||
should "still work" do
|
||||
post = Sources::Strategies.find("https://www.pixiv.net/fanbox/creator/1566167/post/39714")
|
||||
|
||||
Reference in New Issue
Block a user