add new uploads/batch endpoint for handling twitter galleries
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -47,6 +47,7 @@ gem 'streamio-ffmpeg'
|
|||||||
gem 'rubyzip', :require => "zip"
|
gem 'rubyzip', :require => "zip"
|
||||||
gem 'coinbase'
|
gem 'coinbase'
|
||||||
gem 'stripe'
|
gem 'stripe'
|
||||||
|
gem 'twitter'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
21
Gemfile.lock
21
Gemfile.lock
@@ -49,6 +49,7 @@ GEM
|
|||||||
bcrypt (3.1.7)
|
bcrypt (3.1.7)
|
||||||
bcrypt-ruby (3.1.5)
|
bcrypt-ruby (3.1.5)
|
||||||
bcrypt (>= 3.1.3)
|
bcrypt (>= 3.1.3)
|
||||||
|
buftok (0.2.0)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
byebug (3.2.0)
|
byebug (3.2.0)
|
||||||
columnize (~> 0.8)
|
columnize (~> 0.8)
|
||||||
@@ -94,6 +95,7 @@ GEM
|
|||||||
docile (1.1.3)
|
docile (1.1.3)
|
||||||
domain_name (0.5.18)
|
domain_name (0.5.18)
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
|
equalizer (0.0.9)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (2.0.2)
|
execjs (2.0.2)
|
||||||
factory_girl (4.4.0)
|
factory_girl (4.4.0)
|
||||||
@@ -104,8 +106,11 @@ GEM
|
|||||||
hashie (3.3.1)
|
hashie (3.3.1)
|
||||||
highline (1.6.21)
|
highline (1.6.21)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
|
http (0.6.3)
|
||||||
|
http_parser.rb (~> 0.6.0)
|
||||||
http-cookie (1.0.2)
|
http-cookie (1.0.2)
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
|
http_parser.rb (0.6.0)
|
||||||
httparty (0.13.3)
|
httparty (0.13.3)
|
||||||
json (~> 1.8)
|
json (~> 1.8)
|
||||||
multi_xml (>= 0.5.2)
|
multi_xml (>= 0.5.2)
|
||||||
@@ -125,6 +130,8 @@ GEM
|
|||||||
nokogiri (~> 1.4)
|
nokogiri (~> 1.4)
|
||||||
ntlm-http (~> 0.1, >= 0.1.1)
|
ntlm-http (~> 0.1, >= 0.1.1)
|
||||||
webrobots (>= 0.0.9, < 0.2)
|
webrobots (>= 0.0.9, < 0.2)
|
||||||
|
memoizable (0.4.2)
|
||||||
|
thread_safe (~> 0.3, >= 0.3.1)
|
||||||
metaclass (0.0.4)
|
metaclass (0.0.4)
|
||||||
method_source (0.8.2)
|
method_source (0.8.2)
|
||||||
mime-types (1.25.1)
|
mime-types (1.25.1)
|
||||||
@@ -139,6 +146,7 @@ GEM
|
|||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
multi_xml (0.5.5)
|
multi_xml (0.5.5)
|
||||||
multipart-post (2.0.0)
|
multipart-post (2.0.0)
|
||||||
|
naught (1.0.0)
|
||||||
net-http-digest_auth (1.4)
|
net-http-digest_auth (1.4)
|
||||||
net-http-persistent (2.9.4)
|
net-http-persistent (2.9.4)
|
||||||
net-scp (1.2.0)
|
net-scp (1.2.0)
|
||||||
@@ -212,6 +220,7 @@ GEM
|
|||||||
simple_form (3.0.2)
|
simple_form (3.0.2)
|
||||||
actionpack (~> 4.0)
|
actionpack (~> 4.0)
|
||||||
activemodel (~> 4.0)
|
activemodel (~> 4.0)
|
||||||
|
simple_oauth (0.3.1)
|
||||||
simplecov (0.8.2)
|
simplecov (0.8.2)
|
||||||
docile (~> 1.1.0)
|
docile (~> 1.1.0)
|
||||||
multi_json
|
multi_json
|
||||||
@@ -243,6 +252,17 @@ GEM
|
|||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
timecop (0.7.1)
|
timecop (0.7.1)
|
||||||
tins (1.1.0)
|
tins (1.1.0)
|
||||||
|
twitter (5.13.0)
|
||||||
|
addressable (~> 2.3)
|
||||||
|
buftok (~> 0.2.0)
|
||||||
|
equalizer (~> 0.0.9)
|
||||||
|
faraday (~> 0.9.0)
|
||||||
|
http (~> 0.6.0)
|
||||||
|
http_parser.rb (~> 0.6.0)
|
||||||
|
json (~> 1.8)
|
||||||
|
memoizable (~> 0.4.0)
|
||||||
|
naught (~> 1.0)
|
||||||
|
simple_oauth (~> 0.3.0)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
uglifier (2.5.0)
|
uglifier (2.5.0)
|
||||||
@@ -313,6 +333,7 @@ DEPENDENCIES
|
|||||||
term-ansicolor
|
term-ansicolor
|
||||||
therubyracer
|
therubyracer
|
||||||
timecop
|
timecop
|
||||||
|
twitter
|
||||||
uglifier
|
uglifier
|
||||||
unicorn
|
unicorn
|
||||||
vcr
|
vcr
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ div#c-uploads {
|
|||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul#links {
|
||||||
|
margin-bottom: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
label[for="upload_as_pending"] {
|
label[for="upload_as_pending"] {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ class UploadsController < ApplicationController
|
|||||||
respond_with(@upload)
|
respond_with(@upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def batch
|
||||||
|
if params[:url] =~ /twitter/
|
||||||
|
@service = TwitterService.new
|
||||||
|
end
|
||||||
|
@urls = @service.image_urls(params[:url])
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@search = Upload.search(params[:search])
|
@search = Upload.search(params[:search])
|
||||||
@uploads = @search.order("id desc").paginate(params[:page], :limit => params[:limit])
|
@uploads = @search.order("id desc").paginate(params[:page], :limit => params[:limit])
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ module Downloads
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.strategies
|
def self.strategies
|
||||||
[Pixiv, NicoSeiga, Twitpic, DeviantArt, Tumblr, Moebooru, Twitter]
|
[Downloads::RewriteStrategies::Pixiv, Downloads::RewriteStrategies::NicoSeiga, Downloads::RewriteStrategies::Twitpic, Downloads::RewriteStrategies::DeviantArt, Downloads::RewriteStrategies::Tumblr, Downloads::RewriteStrategies::Moebooru, Downloads::RewriteStrategies::Twitter]
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite(url, headers, data = {})
|
def rewrite(url, headers, data = {})
|
||||||
|
|||||||
33
app/logical/twitter_service.rb
Normal file
33
app/logical/twitter_service.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
class TwitterService
|
||||||
|
def client
|
||||||
|
raise "Twitter API keys not set" if Danbooru.config.twitter_api_key.nil?
|
||||||
|
|
||||||
|
@client ||= begin
|
||||||
|
rest_client = Twitter::REST::Client.new do |config|
|
||||||
|
config.consumer_key = Danbooru.config.twitter_api_key
|
||||||
|
config.consumer_secret = Danbooru.config.twitter_api_secret
|
||||||
|
if bearer_token = Cache.get("twitter-api-token")
|
||||||
|
config.bearer_token = bearer_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Cache.put("twitter-api-token", rest_client.bearer_token)
|
||||||
|
|
||||||
|
rest_client
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_urls(tweet_url)
|
||||||
|
attrs = client.status(tweet_url).attrs
|
||||||
|
urls = []
|
||||||
|
attrs[:entities][:media].each do |obj|
|
||||||
|
urls << obj[:media_url]
|
||||||
|
end
|
||||||
|
attrs[:extended_entities][:media].each do |obj|
|
||||||
|
urls << obj[:media_url]
|
||||||
|
end
|
||||||
|
urls.uniq
|
||||||
|
rescue
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
31
app/views/uploads/batch.html.erb
Normal file
31
app/views/uploads/batch.html.erb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<div id="c-uploads">
|
||||||
|
<div id="a-new">
|
||||||
|
<h1>Batch Upload</h1>
|
||||||
|
|
||||||
|
<ul id="links">
|
||||||
|
<% @urls.each.with_index do |url, i| %>
|
||||||
|
<li><%= link_to "Image ##{i}", new_upload_path(:url => url, :ref => params[:url]), :target => "_blank" %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p><%= link_to "Open all links in new windows", "#", :id => "link" %></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Batch Upload - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for(:html_header) do %>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
$("#link").click(function() {
|
||||||
|
$("#links a").each(function(i, v) {
|
||||||
|
window.open(v.href);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render "posts/partials/common/secondary_links" %>
|
||||||
@@ -342,10 +342,10 @@ module Danbooru
|
|||||||
def stripe_publishable_key
|
def stripe_publishable_key
|
||||||
end
|
end
|
||||||
|
|
||||||
def twitter_login
|
def twitter_api_key
|
||||||
end
|
end
|
||||||
|
|
||||||
def twitter_password
|
def twitter_api_secret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -232,7 +232,11 @@ Rails.application.routes.draw do
|
|||||||
get :posts
|
get :posts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :uploads
|
resources :uploads do
|
||||||
|
collection do
|
||||||
|
get :batch
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :users do
|
resources :users do
|
||||||
collection do
|
collection do
|
||||||
get :search
|
get :search
|
||||||
|
|||||||
Reference in New Issue
Block a user