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.input {
input[type="text"] {

View File

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

View File

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

View File

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