potential fix for #2328

This commit is contained in:
r888888888
2014-12-17 14:18:25 -08:00
parent 116b4ea178
commit 43ee2875bf
2 changed files with 12 additions and 2 deletions

View File

@@ -3,12 +3,13 @@ module Downloads
class Error < Exception ; end class Error < Exception ; end
attr_reader :data, :options attr_reader :data, :options
attr_accessor :source, :content_type, :file_path attr_accessor :source, :original_source, :content_type, :file_path
def initialize(source, file_path, options = {}) def initialize(source, file_path, options = {})
# source can potentially get rewritten in the course # source can potentially get rewritten in the course
# of downloading a file, so check it again # of downloading a file, so check it again
@source = source @source = source
@original_source = source
# where to save the download # where to save the download
@file_path = file_path @file_path = file_path
@@ -41,6 +42,7 @@ module Downloads
def after_download(src) def after_download(src)
fix_image_board_sources(src) fix_image_board_sources(src)
fix_twitter_sources(src)
end end
def http_get_streaming(src, datums = {}, options = {}) def http_get_streaming(src, datums = {}, options = {})
@@ -106,5 +108,13 @@ module Downloads
src src
end end
end end
def fix_twitter_sources(src)
if src =~ %r!^https?://pbs\.twimg\.com/! && original_source =~ %r!^https?://twitter\.com/!
original_source
else
src
end
end
end end
end end

View File

@@ -36,7 +36,7 @@
<div class="input"> <div class="input">
<%= f.label :source %> <%= f.label :source %>
<% if params[:url].present? %> <% if params[:url].present? %>
<%= f.text_field :source, :size => 50, :value => @normalized_url %> <%= f.text_field :source, :size => 50, :value => params[:url] %>
<% else %> <% else %>
<%= f.text_field :source, :size => 50 %> <%= f.text_field :source, :size => 50 %>
<% end %> <% end %>