From 8083c7daaea872af119a7e3f3abaa8ea5de4a402 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 20 Apr 2018 15:42:42 -0500 Subject: [PATCH] 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. --- .../stylesheets/common/simple_form.scss | 11 +++++ app/controllers/uploads_controller.rb | 12 ++++-- app/views/uploads/batch.html.erb | 43 +++++++++++-------- test/functional/uploads_controller_test.rb | 7 +++ 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/common/simple_form.scss b/app/assets/stylesheets/common/simple_form.scss index ca697547d..4350da3c3 100644 --- a/app/assets/stylesheets/common/simple_form.scss +++ b/app/assets/stylesheets/common/simple_form.scss @@ -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"] { diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 9821ab9f1..760715ca9 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -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 diff --git a/app/views/uploads/batch.html.erb b/app/views/uploads/batch.html.erb index 1cd12a528..a387f17d0 100644 --- a/app/views/uploads/batch.html.erb +++ b/app/views/uploads/batch.html.erb @@ -2,27 +2,34 @@

Batch Upload

-
- <% @urls.each.with_index do |url, i| %> -
-

- <%= link_to "Image ##{i}", new_upload_path(url: url, ref: params[:url]), target: "_blank" %> -

+ <%= 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? %> +
+ <% @source.image_urls.each.with_index do |url, i| %> +
+

+ <%= link_to "Image ##{i}", new_upload_path(url: url, ref: @url), target: "_blank" %> +

+ + <%= 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 %> -
+
+ <% end %> -

<%= link_to "Open all links in new windows", "#", :id => "link" %>

+

<%= link_to "Open all links in new windows", "#", :id => "link" %>

+
+ <% end %>
diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index df1ec5bbc..80d2cf522 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -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