uploads: fix batch upload page to work without bookmarklet.

* Add a form to the /uploads/batch page so that it can be used without
  the bookmarklet.

* Fix an exception when no url is given.
This commit is contained in:
evazion
2018-04-20 15:42:42 -05:00
parent 83b96b4f3f
commit 8083c7daae
4 changed files with 52 additions and 21 deletions

View File

@@ -71,6 +71,17 @@ form.inline-form {
} }
} }
form.one-line-form {
> input, > div.input {
display: inline;
label {
display: inline;
margin-right: 1em;
}
}
}
div.ui-dialog { div.ui-dialog {
div.input { div.input {
input[type="text"] { input[type="text"] {

View File

@@ -20,9 +20,15 @@ class UploadsController < ApplicationController
end end
def batch def batch
@source = Sources::Site.new(params[:url], :referer_url => params[:ref]) @url = params.dig(:batch, :url) || params[:url]
@source.get @source = nil
@urls = @source.image_urls
if @url
@source = Sources::Site.new(@url, :referer_url => params[:ref])
@source.get
end
respond_with(@source)
end end
def image_proxy def image_proxy

View File

@@ -2,27 +2,34 @@
<div id="a-batch"> <div id="a-batch">
<h1>Batch Upload</h1> <h1>Batch Upload</h1>
<section> <%= simple_form_for(:batch, url: batch_uploads_path, method: :get, defaults: { required: false }, html: { class: "one-line-form" }) do |f| %>
<% @urls.each.with_index do |url, i| %> <%= f.input :url, label: "URL", input_html: { size: 70, value: @url, placeholder: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746" } %>
<div class="upload-preview"> <%= f.submit "Fetch" %>
<p class="caption-top"> <% end %>
<%= link_to "Image ##{i}", new_upload_path(url: url, ref: params[:url]), target: "_blank" %>
</p>
<%= link_to new_upload_path(url: url, ref: params[:url]), target: "_blank" do %> <% if @source.present? %>
<% if ImageProxy.needs_proxy?(url) %> <section>
<%= image_tag(image_proxy_uploads_path(url: url)) %> <% @source.image_urls.each.with_index do |url, i| %>
<% elsif url.is_a?(String) %> <div class="upload-preview">
<%= image_tag url %> <p class="caption-top">
<% else %> <%= link_to "Image ##{i}", new_upload_path(url: url, ref: @url), target: "_blank" %>
Direct Link </p>
<%= link_to new_upload_path(url: url, ref: @url), target: "_blank" do %>
<% if ImageProxy.needs_proxy?(url) %>
<%= image_tag(image_proxy_uploads_path(url: url)) %>
<% elsif url.is_a?(String) %>
<%= image_tag url %>
<% else %>
Direct Link
<% end %>
<% end %> <% end %>
<% end %> </div>
</div> <% end %>
<% end %>
</section>
<p><%= link_to "Open all links in new windows", "#", :id => "link" %></p> <p><%= link_to "Open all links in new windows", "#", :id => "link" %></p>
</section>
<% end %>
</div> </div>
</div> </div>

View File

@@ -23,6 +23,13 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
assert_no_match(/59523577_ugoira0\.jpg/, response.body) assert_no_match(/59523577_ugoira0\.jpg/, response.body)
end end
end end
context "for a blank source" do
should "render" do
get_auth batch_uploads_path, @user
assert_response :success
end
end
end end
context "new action" do context "new action" do