FIX: properly handle images when using 's3_cdn_url'

This commit is contained in:
Régis Hanol 2015-05-26 11:47:33 +02:00
parent 32f91301ef
commit a797f7c664
3 changed files with 8 additions and 2 deletions

View File

@ -111,6 +111,7 @@ module Jobs
end end
# we don't want to pull images hosted on the CDN (if we use one) # we don't want to pull images hosted on the CDN (if we use one)
return false if Discourse.asset_host.present? && URI.parse(Discourse.asset_host).hostname == uri.hostname return false if Discourse.asset_host.present? && URI.parse(Discourse.asset_host).hostname == uri.hostname
return false if Discourse.s3_cdn_url.present? && URI.parse(Discourse.s3_cdn_url).hostname == uri.hostname
# we don't want to pull images hosted on the main domain # we don't want to pull images hosted on the main domain
return false if URI.parse(Discourse.base_url_no_prefix).hostname == uri.hostname return false if URI.parse(Discourse.base_url_no_prefix).hostname == uri.hostname
# check the domains blacklist # check the domains blacklist

View File

@ -128,7 +128,9 @@ class Upload < ActiveRecord::Base
def self.get_from_url(url) def self.get_from_url(url)
return if url.blank? return if url.blank?
# we store relative urls, so we need to remove any host/cdn # we store relative urls, so we need to remove any host/cdn
url = url.gsub(/^#{Discourse.asset_host}/i, "") if Discourse.asset_host.present? url = url.sub(/^#{Discourse.asset_host}/i, "") if Discourse.asset_host.present?
# when using s3, we need to replace with the absolute base url
url = url.sub(/^#{SiteSetting.s3_cdn_url}/i, Discourse.store.absolute_base_url) if SiteSetting.s3_cdn_url.present?
Upload.find_by(url: url) if Discourse.store.has_been_uploaded?(url) Upload.find_by(url: url) if Discourse.store.has_been_uploaded?(url)
end end

View File

@ -32,7 +32,10 @@ module FileStore
end end
def has_been_uploaded?(url) def has_been_uploaded?(url)
url.present? && url.start_with?(absolute_base_url) return false if url.blank?
return true if url.start_with?(absolute_base_url)
return true if SiteSetting.s3_cdn_url.present? && url.start_with?(SiteSetting.s3_cdn_url)
false
end end
def absolute_base_url def absolute_base_url