fixes #2426
This commit is contained in:
@@ -33,6 +33,27 @@ class UploadsController < ApplicationController
|
||||
@urls = @source.image_urls
|
||||
end
|
||||
|
||||
def image_proxy
|
||||
if params[:url].blank? || params[:ref].blank?
|
||||
raise "Must specify url and referer"
|
||||
end
|
||||
|
||||
url = URI.parse(params[:url])
|
||||
headers = {
|
||||
"Referer" => params[:ref],
|
||||
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
|
||||
}
|
||||
|
||||
Net::HTTP.start(url.host, url.port) do |http|
|
||||
resp = http.request_get(url.request_uri, headers)
|
||||
if resp.is_a?(Net::HTTPSuccess)
|
||||
send_data resp.body, type: resp.content_type, disposition: "inline"
|
||||
else
|
||||
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@search = Upload.search(params[:search])
|
||||
@uploads = @search.order("id desc").paginate(params[:page], :limit => params[:limit])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<% if params[:url] %>
|
||||
<%= image_tag(@normalized_url, :title => "Preview", :id => "image") %>
|
||||
<%= image_tag(image_proxy_uploads_path(:url => @normalized_url, :ref => params[:ref]), :title => "Preview", :id => "image") %>
|
||||
|
||||
<ul>
|
||||
<% if @remote_size %>
|
||||
|
||||
@@ -248,6 +248,7 @@ Rails.application.routes.draw do
|
||||
resources :uploads do
|
||||
collection do
|
||||
get :batch
|
||||
get :image_proxy
|
||||
end
|
||||
end
|
||||
resources :users do
|
||||
|
||||
Reference in New Issue
Block a user