potential fix for #2404
This commit is contained in:
@@ -253,7 +253,7 @@
|
||||
|
||||
Danbooru.RelatedTag.find_artist = function(e) {
|
||||
$("#artist-tags").html("<em>Loading...</em>");
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
[]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<div id="source-info">
|
||||
<% if source.try(:available?) %>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url(self)), :id => "fetch-data-bookmarklet", :style => "display: none;" %></p>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url), :id => "fetch-data-bookmarklet", :style => "display: none;" %></p>
|
||||
<p><%= content_tag "span", "Loading #{source.site_name} data...", :id => "loading-data" %></p>
|
||||
<% else %>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
|
||||
|
||||
@@ -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? %>
|
||||
<div class="input">
|
||||
|
||||
Reference in New Issue
Block a user