Implement #2395 for nijie twitter and tumblr
This commit is contained in:
@@ -254,7 +254,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 = $("#upload_source,#post_source");
|
||||||
var referer_url = $("#referer_url");
|
var referer_url = $("#upload_referer_url");
|
||||||
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}).success(Danbooru.RelatedTag.process_artist);
|
$.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}).success(Danbooru.RelatedTag.process_artist);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ module Downloads
|
|||||||
def after_download(src)
|
def after_download(src)
|
||||||
src = fix_image_board_sources(src)
|
src = fix_image_board_sources(src)
|
||||||
src = fix_twitter_sources(src)
|
src = fix_twitter_sources(src)
|
||||||
|
if options[:referer_url].present?
|
||||||
|
src = set_source_to_referer(src)
|
||||||
|
end
|
||||||
src
|
src
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -131,5 +134,14 @@ module Downloads
|
|||||||
src
|
src
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_source_to_referer(src)
|
||||||
|
if Sources::Strategies::Nijie.url_match?(src) || Sources::Strategies::Twitter.url_match?(src) || Sources::Strategies::Tumblr.url_match?(src)
|
||||||
|
strategy = Sources::Site.new(src, :referer_url => options[:referer_url])
|
||||||
|
strategy.referer_url
|
||||||
|
else
|
||||||
|
src
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module Sources
|
|||||||
:artist_commentary_desc, :to => :strategy
|
:artist_commentary_desc, :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, Strategies::Tumblr]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(url, options = {})
|
def initialize(url, options = {})
|
||||||
|
|||||||
28
app/logical/sources/strategies/tumblr.rb
Normal file
28
app/logical/sources/strategies/tumblr.rb
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
module Sources::Strategies
|
||||||
|
class Tumblr < Base
|
||||||
|
def self.url_match?(url)
|
||||||
|
url =~ %r{^https?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(\d+)\..+$} || url =~ %r{^https?://[^.]+\.tumblr\.com/(?:post|image)/\d+}
|
||||||
|
end
|
||||||
|
|
||||||
|
def referer_url
|
||||||
|
if @referer_url =~ %r{^https?://[^.]+\.tumblr\.com/post/\d+} && @url =~ %r{^https?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(\d+)\..+$}
|
||||||
|
@referer_url
|
||||||
|
elsif @referer_url =~ %r{^https?://[^.]+\.tumblr\.com/image/\d+} && @url =~ %r{^https?://.+\.tumblr\.com/(?:\w+/)?(?:tumblr_)?(\w+_)(\d+)\..+$}
|
||||||
|
@referer_url.sub("/image/", "/post/")
|
||||||
|
else
|
||||||
|
@url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
def site_name
|
||||||
|
"Tumblr"
|
||||||
|
end
|
||||||
|
|
||||||
|
def get
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,7 +6,8 @@ class Upload < ActiveRecord::Base
|
|||||||
|
|
||||||
attr_accessor :file, :image_width, :image_height, :file_ext, :md5,
|
attr_accessor :file, :image_width, :image_height, :file_ext, :md5,
|
||||||
:file_size, :as_pending, :artist_commentary_title,
|
:file_size, :as_pending, :artist_commentary_title,
|
||||||
:artist_commentary_desc, :include_artist_commentary
|
:artist_commentary_desc, :include_artist_commentary,
|
||||||
|
:referer_url
|
||||||
belongs_to :uploader, :class_name => "User"
|
belongs_to :uploader, :class_name => "User"
|
||||||
belongs_to :post
|
belongs_to :post
|
||||||
before_validation :initialize_uploader, :on => :create
|
before_validation :initialize_uploader, :on => :create
|
||||||
@@ -20,7 +21,8 @@ class Upload < ActiveRecord::Base
|
|||||||
:file_size, :as_pending, :source, :file_path, :content_type, :rating,
|
:file_size, :as_pending, :source, :file_path, :content_type, :rating,
|
||||||
:tag_string, :status, :backtrace, :post_id, :md5_confirmation,
|
:tag_string, :status, :backtrace, :post_id, :md5_confirmation,
|
||||||
:parent_id, :server, :artist_commentary_title,
|
:parent_id, :server, :artist_commentary_title,
|
||||||
:artist_commentary_desc, :include_artist_commentary
|
:artist_commentary_desc, :include_artist_commentary,
|
||||||
|
:referer_url
|
||||||
|
|
||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def uploader_is_not_limited
|
def uploader_is_not_limited
|
||||||
@@ -379,7 +381,7 @@ class Upload < ActiveRecord::Base
|
|||||||
# Downloads the file to destination_path
|
# Downloads the file to destination_path
|
||||||
def download_from_source(destination_path)
|
def download_from_source(destination_path)
|
||||||
self.file_path = destination_path
|
self.file_path = destination_path
|
||||||
download = Downloads::File.new(source, destination_path)
|
download = Downloads::File.new(source, destination_path, :referer_url => referer_url)
|
||||||
download.download!
|
download.download!
|
||||||
ugoira_service.load(download.data)
|
ugoira_service.load(download.data)
|
||||||
download.source
|
download.source
|
||||||
|
|||||||
@@ -15,7 +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) %>
|
<%= f.hidden_field :referer_url, :value => @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