Upload preview: use normalized image url

This means that the preview will work even when the user doesn't use the
direct image link. e.g. The user can use the bookmarklet on Pixiv
mode=medium pages.
This commit is contained in:
Toks
2014-04-28 15:29:31 -04:00
parent e84934bf78
commit cc3c6d989f
2 changed files with 10 additions and 1 deletions

View File

@@ -8,6 +8,15 @@ class UploadsController < ApplicationController
@upload = Upload.new(:rating => "q")
if params[:url]
@post = Post.find_by_source(params[:url])
@normalized_url = params[:url]
headers = {
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
}
Downloads::Strategies::Base.strategies.each do |strategy|
@normalized_url, headers = strategy.new.rewrite(@normalized_url, headers)
end
begin
@source = Sources::Site.new(params[:url])
rescue Exception

View File

@@ -1,5 +1,5 @@
<% if params[:url] %>
<%= image_tag(params[:url], :title => "Preview", :id => "image") %>
<%= image_tag(@normalized_url, :title => "Preview", :id => "image") %>
<% if params[:ref] %>
<p><strong>Referrer: </strong> <%= params[:ref] %></p>
<% end %>