Merge pull request #3379 from evazion/fix-3377
Fix #3377: Batch bookmarklet doesn't fetch artist/tags from twitter
This commit is contained in:
@@ -125,7 +125,7 @@ module Downloads
|
|||||||
|
|
||||||
def set_source_to_referer(src, referer)
|
def set_source_to_referer(src, referer)
|
||||||
if Sources::Strategies::Nijie.url_match?(src) ||
|
if Sources::Strategies::Nijie.url_match?(src) ||
|
||||||
Sources::Strategies::Twitter.url_match?(src) ||
|
Sources::Strategies::Twitter.url_match?(src) || Sources::Strategies::Twitter.url_match?(referer)
|
||||||
Sources::Strategies::Pawoo.url_match?(src) ||
|
Sources::Strategies::Pawoo.url_match?(src) ||
|
||||||
Sources::Strategies::Tumblr.url_match?(src) || Sources::Strategies::Tumblr.url_match?(referer)
|
Sources::Strategies::Tumblr.url_match?(src) || Sources::Strategies::Tumblr.url_match?(referer)
|
||||||
Sources::Strategies::ArtStation.url_match?(src) || Sources::Strategies::ArtStation.url_match?(referer)
|
Sources::Strategies::ArtStation.url_match?(src) || Sources::Strategies::ArtStation.url_match?(referer)
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ module Sources::Strategies
|
|||||||
attr_reader :image_urls
|
attr_reader :image_urls
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! || url =~ %r{https?://pbs\.twimg\.com/media/}
|
self.status_id_from_url(url).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url
|
def referer_url
|
||||||
if @referer_url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! && @url =~ %r{https?://pbs\.twimg\.com/media/}
|
if self.class.url_match?(@referer_url)
|
||||||
@referer_url
|
@referer_url
|
||||||
else
|
else
|
||||||
@url
|
@url
|
||||||
@@ -19,7 +19,6 @@ module Sources::Strategies
|
|||||||
end
|
end
|
||||||
|
|
||||||
def api_response
|
def api_response
|
||||||
status_id = status_id_from_url(url)
|
|
||||||
@api_response ||= TwitterService.new.client.status(status_id, tweet_mode: "extended")
|
@api_response ||= TwitterService.new.client.status(status_id, tweet_mode: "extended")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -62,11 +61,15 @@ module Sources::Strategies
|
|||||||
desc.strip
|
desc.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_id_from_url(url)
|
def status_id
|
||||||
|
self.class.status_id_from_url(referer_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.status_id_from_url(url)
|
||||||
if url =~ %r{^https?://(?:mobile\.)?twitter\.com/\w+/status/(\d+)}
|
if url =~ %r{^https?://(?:mobile\.)?twitter\.com/\w+/status/(\d+)}
|
||||||
$1.to_i
|
$1.to_i
|
||||||
else
|
else
|
||||||
raise Sources::Error.new("Couldn't get status ID from URL: #{url}")
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,10 +3,20 @@ require 'test_helper'
|
|||||||
class SourcesControllerTest < ActionController::TestCase
|
class SourcesControllerTest < ActionController::TestCase
|
||||||
context "The sources controller" do
|
context "The sources controller" do
|
||||||
context "show action" do
|
context "show action" do
|
||||||
should "work" do
|
should "work for a pixiv URL" do
|
||||||
get :show, { url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", format: "json" }
|
get :show, { url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", format: "json" }
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "work for a direct twitter URL with referer" do
|
||||||
|
get :show, {
|
||||||
|
url: "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large",
|
||||||
|
ref: "https://twitter.com/nounproject/status/540944400767922176",
|
||||||
|
format: "json"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -123,6 +123,21 @@ module Sources
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "The source site for a direct image and a referer" do
|
||||||
|
setup do
|
||||||
|
@site = Sources::Site.new("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large", referer_url: "https://twitter.com/nounproject/status/540944400767922176")
|
||||||
|
@site.get
|
||||||
|
end
|
||||||
|
|
||||||
|
should "get the artist name" do
|
||||||
|
assert_equal("Noun Project", @site.artist_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "get the image url" do
|
||||||
|
assert_equal("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig", @site.image_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "A tweet" do
|
context "A tweet" do
|
||||||
setup do
|
setup do
|
||||||
@site = Sources::Site.new("https://twitter.com/noizave/status/875768175136317440")
|
@site = Sources::Site.new("https://twitter.com/noizave/status/875768175136317440")
|
||||||
|
|||||||
Reference in New Issue
Block a user