potential fix for #2404
This commit is contained in:
@@ -253,7 +253,7 @@
|
|||||||
|
|
||||||
Danbooru.RelatedTag.find_artist = function(e) {
|
Danbooru.RelatedTag.find_artist = function(e) {
|
||||||
$("#artist-tags").html("<em>Loading...</em>");
|
$("#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);
|
$.get("/artists/finder.json", {"url": url.val()}).success(Danbooru.RelatedTag.process_artist);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class SourcesController < ApplicationController
|
|||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@source = Sources::Site.new(params[:url])
|
@source = Sources::Site.new(params[:url], :referer_url => params[:ref])
|
||||||
@source.get
|
@source.get
|
||||||
|
|
||||||
respond_with(@source) do |format|
|
respond_with(@source) do |format|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class UploadsController < ApplicationController
|
|||||||
extract_artist_commentary(@upload, data)
|
extract_artist_commentary(@upload, data)
|
||||||
|
|
||||||
begin
|
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
|
@remote_size = Downloads::File.new(@normalized_url, ".").size
|
||||||
rescue Exception
|
rescue Exception
|
||||||
end
|
end
|
||||||
@@ -28,7 +28,7 @@ class UploadsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def batch
|
def batch
|
||||||
@source = Sources::Site.new(params[:url])
|
@source = Sources::Site.new(params[:url], :referer_url => params[:ref])
|
||||||
@source.get
|
@source.get
|
||||||
@urls = @source.image_urls
|
@urls = @source.image_urls
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,22 +3,22 @@
|
|||||||
module Sources
|
module Sources
|
||||||
class Site
|
class Site
|
||||||
attr_reader :url, :strategy
|
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,
|
:profile_url, :image_url, :tags, :artist_record, :unique_id,
|
||||||
:page_count, :file_url, :ugoira_frame_data, :image_urls,
|
:page_count, :file_url, :ugoira_frame_data, :image_urls,
|
||||||
:has_artist_commentary?, :artist_commentary_title,
|
:has_artist_commentary?, :artist_commentary_title,
|
||||||
:artist_commentary_desc, :to => :strategy
|
:artist_commentary_desc, :referer_url, :to => :strategy
|
||||||
|
|
||||||
def self.strategies
|
def self.strategies
|
||||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter]
|
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(url)
|
def initialize(url, options = {})
|
||||||
@url = url
|
@url = url
|
||||||
|
|
||||||
Site.strategies.each do |strategy|
|
Site.strategies.each do |strategy|
|
||||||
if strategy.url_match?(url)
|
if strategy.url_match?(url)
|
||||||
@strategy = strategy.new(url)
|
@strategy = strategy.new(url, options[:referer_url])
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class Base
|
class Base
|
||||||
attr_reader :url
|
attr_reader :url, :referer_url
|
||||||
attr_reader :artist_name, :profile_url, :image_url, :tags, :page_count
|
attr_reader :artist_name, :profile_url, :image_url, :tags, :page_count
|
||||||
attr_reader :artist_commentary_title, :artist_commentary_desc
|
attr_reader :artist_commentary_title, :artist_commentary_desc
|
||||||
|
|
||||||
@@ -9,8 +9,9 @@ module Sources
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(url)
|
def initialize(url, referer_url)
|
||||||
@url = url
|
@url = url
|
||||||
|
@referer_url = referer_url
|
||||||
@page_count = 1
|
@page_count = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,10 +70,6 @@ module Sources
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
|
|
||||||
def image_urls
|
def image_urls
|
||||||
[image_url]
|
[image_url]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ module Sources
|
|||||||
url =~ /^https?:\/\/(?:.+?\.)?deviantart\.(?:com|net)/
|
url =~ /^https?:\/\/(?:.+?\.)?deviantart\.(?:com|net)/
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
def referer_url
|
||||||
if template.params[:ref] =~ /deviantart\.com\/art\// && template.params[:url] =~ /https?:\/\/(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net\//
|
if @referer_url =~ /deviantart\.com\/art\// && @url =~ /https?:\/\/(?:fc|th|pre|orig|img)\d{2}\.deviantart\.net\//
|
||||||
template.params[:ref]
|
@referer_url
|
||||||
else
|
else
|
||||||
template.params[:url]
|
@url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ module Sources
|
|||||||
url =~ /^https?:\/\/(?:\w+\.)?nico(?:seiga|video)\.jp/
|
url =~ /^https?:\/\/(?:\w+\.)?nico(?:seiga|video)\.jp/
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
def referer_url
|
||||||
if template.params[:ref] =~ /seiga\.nicovideo\.jp\/seiga\/im\d+/ && template.params[:url] =~ /http:\/\/lohas\.nicoseiga\.jp\/priv\//
|
if @referer_url =~ /seiga\.nicovideo\.jp\/seiga\/im\d+/ && @url =~ /http:\/\/lohas\.nicoseiga\.jp\/priv\//
|
||||||
template.params[:ref]
|
@referer_url
|
||||||
else
|
else
|
||||||
template.params[:url]
|
@url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
def referer_url(template)
|
||||||
if template.params[:ref] =~ /nijie\.info\/view\.php.+id=\d+/ && template.params[:url] =~ /pic\d+\.nijie.info\/nijie_picture\//
|
if @referer_url =~ /nijie\.info\/view\.php.+id=\d+/ && @url =~ /pic\d+\.nijie.info\/nijie_picture\//
|
||||||
template.params[:ref]
|
@referer_url
|
||||||
else
|
else
|
||||||
template.params[:url]
|
@url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ module Sources
|
|||||||
url =~ /#{WEB}|#{IMG}|#{I12}/i
|
url =~ /#{WEB}|#{IMG}|#{I12}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
def referer_url
|
||||||
if template.params[:ref] =~ /pixiv\.net\/member_illust.+mode=medium/ && template.params[:url] =~ /#{IMG}|#{I12}/
|
if @referer_url =~ /pixiv\.net\/member_illust.+mode=medium/ && @url =~ /#{IMG}|#{I12}/
|
||||||
template.params[:ref]
|
@referer_url
|
||||||
else
|
else
|
||||||
template.params[:url]
|
@url
|
||||||
end
|
end
|
||||||
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/}
|
url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! || url =~ %r{https?://pbs\.twimg\.com/media/}
|
||||||
end
|
end
|
||||||
|
|
||||||
def referer_url(template)
|
def referer_url
|
||||||
if template.params[:ref] =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! && template.params[:url] =~ %r{https?://pbs\.twimg\.com/media/}
|
if @referer_url =~ %r!https?://(?:mobile\.)?twitter\.com/\w+/status/\d+! && @url =~ %r{https?://pbs\.twimg\.com/media/}
|
||||||
template.params[:ref]
|
@referer_url
|
||||||
else
|
else
|
||||||
template.params[:url]
|
@url
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
[]
|
[]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div id="source-info">
|
<div id="source-info">
|
||||||
<% if source.try(:available?) %>
|
<% 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>
|
<p><%= content_tag "span", "Loading #{source.site_name} data...", :id => "loading-data" %></p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
|
<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| %>
|
<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => "form"}) do |f| %>
|
||||||
<%= hidden_field_tag :normalized_url, @normalized_url %>
|
<%= hidden_field_tag :normalized_url, @normalized_url %>
|
||||||
|
<%= hidden_field_tag :referer_url, @source.try(:referer_url) %>
|
||||||
|
|
||||||
<% if CurrentUser.is_contributor? %>
|
<% if CurrentUser.is_contributor? %>
|
||||||
<div class="input">
|
<div class="input">
|
||||||
|
|||||||
Reference in New Issue
Block a user