uploads: remove batch upload page.

* Make /uploads/batch redirect to /uploads/new.
* Remove /uploads/image_proxy.
This commit is contained in:
evazion
2022-02-21 00:03:43 -06:00
parent 3da9c1574f
commit 68ba447494
13 changed files with 4 additions and 166 deletions

View File

@@ -15,19 +15,6 @@ class UploadsController < ApplicationController
respond_with(@upload)
end
def batch
authorize Upload
@url = params.dig(:batch, :url) || params[:url]
@source = Sources::Strategies.find(@url, params[:ref]) if @url.present?
respond_with(@source)
end
def image_proxy
authorize Upload
resp = ImageProxy.get_image(params[:url])
send_data resp.body, type: resp.mime_type, disposition: "inline"
end
def index
@mode = params.fetch(:mode, "gallery")

View File

@@ -21,10 +21,6 @@ Upload.initialize_all = function() {
});
}
if ($("#c-uploads #a-batch").length) {
$(document).on("click.danbooru", "#c-uploads #a-batch #link", Upload.batch_open_all);
}
Upload.loadAssets();
}
@@ -71,10 +67,6 @@ Upload.toggle_translation = function() {
$(".commentary-translation").slideToggle();
};
Upload.batch_open_all = function() {
$(".upload-preview > a").each((_i, link) => window.open(link.href));
};
$(function() {
Upload.initialize_all();
});

View File

@@ -44,28 +44,4 @@ div#c-uploads {
margin-right: 1.5em;
}
}
div.upload-preview {
display: inline-block;
> a {
width: 154px;
height: 154px;
margin: 0 10px 10px 0;
display: inline-block;
img {
margin: auto;
border: 2px solid transparent;
max-width: 154px;
max-height: 154px;
}
}
.caption-top {
font-size: var(--text-sm);
margin-bottom: 0;
}
}
}

View File

@@ -1,24 +0,0 @@
# frozen_string_literal: true
class ImageProxy
class Error < StandardError; end
def self.needs_proxy?(url)
fake_referer_for(url).present?
end
def self.fake_referer_for(url)
Sources::Strategies.find(url).headers["Referer"]
end
def self.get_image(url)
raise Error, "URL not present" unless url.present?
raise Error, "Proxy not allowed for this url (url=#{url})" unless needs_proxy?(url)
referer = fake_referer_for(url)
response = Danbooru::Http.timeout(30).headers(Referer: referer).get(url)
raise Error, "Couldn't proxy image (code=#{response.status}, url=#{url})" unless response.status.success?
response
end
end

View File

@@ -211,12 +211,6 @@ module Sources
nil
end
# Subclasses should merge in any required headers needed to access resources
# on the site.
def headers
{}
end
# Download the file at the given url, or at the main image url by default.
def download_file!(download_url = image_url)
response, file = http_downloader.download_media(download_url)

View File

@@ -100,10 +100,6 @@ module Sources
tags.map(&:first).flat_map(&method(:translate_tag)).uniq.sort
end
def headers
{ "Referer" => "http://#{site_name}" }
end
# Moebooru returns an empty array when doing an md5:<hash> search for a
# deleted post. Because of this, api_response may be empty in some cases.
def api_response

View File

@@ -177,10 +177,6 @@ module Sources
api_illust[:description]
end
def headers
{ "Referer" => "https://www.pixiv.net" }
end
def normalize_for_source
return nil if illust_id.blank?
"https://www.pixiv.net/artworks/#{illust_id}"

View File

@@ -93,10 +93,6 @@ module Sources
image_urls.map { |img| img.gsub(%r{.cn/\w+/(\w+)}, '.cn/orj360/\1') }
end
def headers
{ "Referer" => "https://weibo.com" }
end
def page_url
if api_response.present?
artist_id = api_response["user"]["id"]

View File

@@ -9,14 +9,6 @@ class UploadPolicy < ApplicationPolicy
user.is_admin? || record.uploader_id == user.id
end
def batch?
unbanned?
end
def image_proxy?
unbanned?
end
def permitted_attributes
[:source, :referer_url, files: {}]
end

View File

@@ -6,7 +6,6 @@
<p>
<%= link_to "Post to #{Danbooru.config.app_name}", "javascript:location.href='#{request.protocol + request.host_with_port}/uploads/new?url='+encodeURIComponent(location.href)+'&ref='+encodeURIComponent(document.referrer)" %>
| <%= link_to "Batch to #{Danbooru.config.app_name}", "javascript:location.href='#{request.protocol + request.host_with_port}/uploads/batch?url='+encodeURIComponent(location.href)" %>
</p>
<div class="prose">

View File

@@ -1,37 +0,0 @@
<% page_title "Batch Upload" %>
<%= render "uploads/secondary_links" %>
<div id="c-uploads">
<div id="a-batch">
<h1>Batch Upload</h1>
<%= 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 %>
<% if @source.present? %>
<section>
<% @source.image_urls.zip(@source.preview_urls).each.with_index do |(url, preview_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: preview_url)) %>
<% elsif url.is_a?(String) %>
<%= image_tag preview_url %>
<% else %>
Direct Link
<% end %>
<% end %>
</div>
<% end %>
<p><%= link_to "Open all links in new tabs", "#", :id => "link" %></p>
</section>
<% end %>
</div>
</div>

View File

@@ -249,8 +249,7 @@ Rails.application.routes.draw do
resources :tag_implications, only: [:show, :index, :destroy]
resources :uploads do
collection do
get :batch
get :image_proxy
get :batch, to: redirect(path: "/uploads/new")
end
resources :upload_media_assets, only: [:show, :index], path: "assets"
end

View File

@@ -6,39 +6,11 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
@user = create(:user)
end
context "image proxy action" do
should "work" do
url = "https://i.pximg.net/img-original/img/2017/11/21/17/06/44/65985331_p0.png"
get_auth image_proxy_uploads_path, @user, params: { url: url }
assert_response :success
assert_equal("image/png", response.media_type)
assert_equal(15_573, response.body.size)
end
end
context "batch action" do
context "for twitter galleries" do
should "render" do
skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key
get_auth batch_uploads_path, @user, params: {:url => "https://twitter.com/lvlln/status/567054278486151168"}
assert_response :success
end
end
should "redirect to the new upload page" do
get batch_uploads_path(url: "https://twitter.com/lvlln/status/567054278486151168")
context "for pixiv ugoira galleries" do
should "render" do
get_auth batch_uploads_path, @user, params: {:url => "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=59523577"}
assert_response :success
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
assert_redirected_to new_upload_path(url: "https://twitter.com/lvlln/status/567054278486151168")
end
end