From cc3c6d989fbf35d8ac69f0a61519e54acf80b5b3 Mon Sep 17 00:00:00 2001 From: Toks Date: Mon, 28 Apr 2014 15:29:31 -0400 Subject: [PATCH] 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. --- app/controllers/uploads_controller.rb | 9 +++++++++ app/views/uploads/_image.html.erb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 94a94a7ff..9c69e7381 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -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 diff --git a/app/views/uploads/_image.html.erb b/app/views/uploads/_image.html.erb index c9989e77a..d37bb2c20 100644 --- a/app/views/uploads/_image.html.erb +++ b/app/views/uploads/_image.html.erb @@ -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] %>

Referrer: <%= params[:ref] %>

<% end %>