Tumblr: fix crash when uploading image links from custom domains

This commit is contained in:
nonamethanks
2022-10-01 00:24:24 +02:00
parent 1d7caf703c
commit 775326dc37
2 changed files with 14 additions and 2 deletions

View File

@@ -120,11 +120,11 @@ class Source::Extractor
end
def artist_name
parsed_url.blog_name || parsed_referer&.blog_name || post_url_from_image_html&.blog_name
parsed_url.blog_name || parsed_referer&.blog_name || post_url_from_image_html&.try(:blog_name) # Don't crash with custom domains
end
def work_id
parsed_url.work_id || parsed_referer&.work_id || post_url_from_image_html&.work_id
parsed_url.work_id || parsed_referer&.work_id || post_url_from_image_html&.try(:work_id)
end
def api_response

View File

@@ -186,6 +186,18 @@ module Sources
)
end
context "A tumblr image url for which the extractable post url is a custom domain" do
strategy_should_work(
"https://64.media.tumblr.com/591b370b9deb7c6ef33d8c18dc2c8db5/tumblr_ph5huubDdz1w0f6yio1_1280.jpg",
image_urls: ["https://media.tumblr.com/591b370b9deb7c6ef33d8c18dc2c8db5/tumblr_ph5huubDdz1w0f6yio1_1280.jpg"],
profile_url: nil,
page_url: "https://compllege.com/post/181217216191"
# XXX this fails on purpose pending implementation of support for custom Tumblr domains
# Right now, if we extract and save the custom url as source, then next time the source is fetched the user won't be able to fetch anything from it, which can be confusing.
# A possible solution could be doing a head request for unknown domains in Source::Extractor::Null to check if they're custom tumblr domains
)
end
context "generating page urls" do
should "work" do
source1 = "https://octrain1020.tumblr.com/post/190713122589"