add new uploads/batch endpoint for handling twitter galleries

This commit is contained in:
r888888888
2015-02-09 16:29:00 -08:00
parent 0c00bba65d
commit e57cad7b0a
9 changed files with 105 additions and 4 deletions

View File

@@ -47,6 +47,7 @@ gem 'streamio-ffmpeg'
gem 'rubyzip', :require => "zip"
gem 'coinbase'
gem 'stripe'
gem 'twitter'
# needed for looser jpeg header compat
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"

View File

@@ -49,6 +49,7 @@ GEM
bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
buftok (0.2.0)
builder (3.2.2)
byebug (3.2.0)
columnize (~> 0.8)
@@ -94,6 +95,7 @@ GEM
docile (1.1.3)
domain_name (0.5.18)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.9)
erubis (2.7.0)
execjs (2.0.2)
factory_girl (4.4.0)
@@ -104,8 +106,11 @@ GEM
hashie (3.3.1)
highline (1.6.21)
hike (1.2.3)
http (0.6.3)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
http_parser.rb (0.6.0)
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
@@ -125,6 +130,8 @@ GEM
nokogiri (~> 1.4)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
metaclass (0.0.4)
method_source (0.8.2)
mime-types (1.25.1)
@@ -139,6 +146,7 @@ GEM
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
naught (1.0.0)
net-http-digest_auth (1.4)
net-http-persistent (2.9.4)
net-scp (1.2.0)
@@ -212,6 +220,7 @@ GEM
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
simple_oauth (0.3.1)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
@@ -243,6 +252,17 @@ GEM
tilt (1.4.1)
timecop (0.7.1)
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)
thread_safe (~> 0.1)
uglifier (2.5.0)
@@ -313,6 +333,7 @@ DEPENDENCIES
term-ansicolor
therubyracer
timecop
twitter
uglifier
unicorn
vcr

View File

@@ -4,6 +4,10 @@ div#c-uploads {
margin-bottom: 2em;
}
ul#links {
margin-bottom: 1em;
}
label[for="upload_as_pending"] {
display: inline;
}

View File

@@ -26,6 +26,13 @@ class UploadsController < ApplicationController
respond_with(@upload)
end
def batch
if params[:url] =~ /twitter/
@service = TwitterService.new
end
@urls = @service.image_urls(params[:url])
end
def index
@search = Upload.search(params[:search])
@uploads = @search.order("id desc").paginate(params[:page], :limit => params[:limit])

View File

@@ -6,7 +6,7 @@ module Downloads
end
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
def rewrite(url, headers, data = {})

View 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

View 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" %>

View File

@@ -342,10 +342,10 @@ module Danbooru
def stripe_publishable_key
end
def twitter_login
def twitter_api_key
end
def twitter_password
def twitter_api_secret
end
end
end

View File

@@ -232,7 +232,11 @@ Rails.application.routes.draw do
get :posts
end
end
resources :uploads
resources :uploads do
collection do
get :batch
end
end
resources :users do
collection do
get :search