diff --git a/app/assets/javascripts/related_tag.js b/app/assets/javascripts/related_tag.js index 3247cf651..ba7c6ce8f 100644 --- a/app/assets/javascripts/related_tag.js +++ b/app/assets/javascripts/related_tag.js @@ -253,7 +253,7 @@ Danbooru.RelatedTag.find_artist = function(e) { $("#artist-tags").html("Loading..."); - var url = $("#upload_source,#post_source"); + var url = $("#referer_url,#upload_source,#post_source"); $.get("/artists/finder.json", {"url": url.val()}).success(Danbooru.RelatedTag.process_artist); e.preventDefault(); } diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index bf4bcec1c..c603f56c9 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -3,7 +3,7 @@ class SourcesController < ApplicationController respond_to :json def show - @source = Sources::Site.new(params[:url]) + @source = Sources::Site.new(params[:url], :referer_url => params[:ref]) @source.get respond_with(@source) do |format| diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 769a23f86..ae72e661f 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -19,7 +19,7 @@ class UploadsController < ApplicationController extract_artist_commentary(@upload, data) begin - @source = Sources::Site.new(params[:url]) + @source = Sources::Site.new(params[:url], :referer_url => params[:ref]) @remote_size = Downloads::File.new(@normalized_url, ".").size rescue Exception end @@ -28,7 +28,7 @@ class UploadsController < ApplicationController end def batch - @source = Sources::Site.new(params[:url]) + @source = Sources::Site.new(params[:url], :referer_url => params[:ref]) @source.get @urls = @source.image_urls end diff --git a/app/logical/sources/site.rb b/app/logical/sources/site.rb index f61220c63..df304e8c0 100644 --- a/app/logical/sources/site.rb +++ b/app/logical/sources/site.rb @@ -3,22 +3,22 @@ module Sources class Site attr_reader :url, :strategy - delegate :get, :get_size, :referer_url, :site_name, :artist_name, + delegate :get, :get_size, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :image_urls, :has_artist_commentary?, :artist_commentary_title, - :artist_commentary_desc, :to => :strategy + :artist_commentary_desc, :referer_url, :to => :strategy def self.strategies [Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter] end - def initialize(url) + def initialize(url, options = {}) @url = url Site.strategies.each do |strategy| if strategy.url_match?(url) - @strategy = strategy.new(url) + @strategy = strategy.new(url, options[:referer_url]) break end end diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index 1d357f5ee..b9f0f9a5d 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -1,7 +1,7 @@ module Sources module Strategies class Base - attr_reader :url + attr_reader :url, :referer_url attr_reader :artist_name, :profile_url, :image_url, :tags, :page_count attr_reader :artist_commentary_title, :artist_commentary_desc @@ -9,8 +9,9 @@ module Sources false end - def initialize(url) + def initialize(url, referer_url) @url = url + @referer_url = referer_url @page_count = 1 end @@ -69,10 +70,6 @@ module Sources end end - def referer_url(template) - raise NotImplementedError - end - def image_urls [image_url] end diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index 19306ea5b..f0fd0a326 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -5,11 +5,11 @@ module Sources url =~ /^https?:\/\/(?:.+?\.)?deviantart\.(?:com|net)/ end - def referer_url(template) - if template.params[:ref] =~ /deviantart\.com\/art\// && template.params[:url] =~ /https?:\/\/(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net\// - template.params[:ref] + def referer_url + if @referer_url =~ /deviantart\.com\/art\// && @url =~ /https?:\/\/(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net\// + @referer_url else - template.params[:url] + @url end end diff --git a/app/logical/sources/strategies/nico_seiga.rb b/app/logical/sources/strategies/nico_seiga.rb index 2ef00f579..92e2befea 100644 --- a/app/logical/sources/strategies/nico_seiga.rb +++ b/app/logical/sources/strategies/nico_seiga.rb @@ -5,11 +5,11 @@ module Sources url =~ /^https?:\/\/(?:\w+\.)?nico(?:seiga|video)\.jp/ end - def referer_url(template) - if template.params[:ref] =~ /seiga\.nicovideo\.jp\/seiga\/im\d+/ && template.params[:url] =~ /http:\/\/lohas\.nicoseiga\.jp\/priv\// - template.params[:ref] + def referer_url + if @referer_url =~ /seiga\.nicovideo\.jp\/seiga\/im\d+/ && @url =~ /http:\/\/lohas\.nicoseiga\.jp\/priv\// + @referer_url else - template.params[:url] + @url end end diff --git a/app/logical/sources/strategies/nijie.rb b/app/logical/sources/strategies/nijie.rb index 1f5e7702e..1af62d40f 100644 --- a/app/logical/sources/strategies/nijie.rb +++ b/app/logical/sources/strategies/nijie.rb @@ -6,10 +6,10 @@ module Sources end def referer_url(template) - if template.params[:ref] =~ /nijie\.info\/view\.php.+id=\d+/ && template.params[:url] =~ /pic\d+\.nijie.info\/nijie_picture\// - template.params[:ref] + if @referer_url =~ /nijie\.info\/view\.php.+id=\d+/ && @url =~ /pic\d+\.nijie.info\/nijie_picture\// + @referer_url else - template.params[:url] + @url end end diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index 3c333eb23..e5c19c1b6 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -19,11 +19,11 @@ module Sources url =~ /#{WEB}|#{IMG}|#{I12}/i end - def referer_url(template) - if template.params[:ref] =~ /pixiv\.net\/member_illust.+mode=medium/ && template.params[:url] =~ /#{IMG}|#{I12}/ - template.params[:ref] + def referer_url + if @referer_url =~ /pixiv\.net\/member_illust.+mode=medium/ && @url =~ /#{IMG}|#{I12}/ + @referer_url else - template.params[:url] + @url end end diff --git a/app/logical/sources/strategies/twitter.rb b/app/logical/sources/strategies/twitter.rb index b9fd1dda3..b9f796342 100644 --- a/app/logical/sources/strategies/twitter.rb +++ b/app/logical/sources/strategies/twitter.rb @@ -4,13 +4,13 @@ module Sources::Strategies url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! || url =~ %r{https?://pbs\.twimg\.com/media/} end - def referer_url(template) - if template.params[:ref] =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! && template.params[:url] =~ %r{https?://pbs\.twimg\.com/media/} - template.params[:ref] - else - template.params[:url] - end + def referer_url + if @referer_url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! && @url =~ %r{https?://pbs\.twimg\.com/media/} + @referer_url + else + @url end + end def tags [] diff --git a/app/views/sources/_info.html.erb b/app/views/sources/_info.html.erb index 8ae9928cd..ddb7cd87e 100644 --- a/app/views/sources/_info.html.erb +++ b/app/views/sources/_info.html.erb @@ -4,7 +4,7 @@
<% if source.try(:available?) %> -

<%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url(self)), :id => "fetch-data-bookmarklet", :style => "display: none;" %>

+

<%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url), :id => "fetch-data-bookmarklet", :style => "display: none;" %>

<%= content_tag "span", "Loading #{source.site_name} data...", :id => "loading-data" %>

<% else %>

<%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %>

diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index de7c0af94..a1f9189f1 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -15,6 +15,7 @@ <%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => "form"}) do |f| %> <%= hidden_field_tag :normalized_url, @normalized_url %> + <%= hidden_field_tag :referer_url, @source.try(:referer_url) %> <% if CurrentUser.is_contributor? %>