FIX: Allow shared CDN for s3 and assets
This commit is contained in:
parent
dcbaf2f213
commit
b9a343afe7
|
@ -77,7 +77,7 @@ 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.sub(Discourse.asset_host, "") if Discourse.asset_host.present?
|
url = url.sub(Discourse.asset_host, "") if Discourse.asset_host.present? && Discourse.asset_host != SiteSetting.Upload.s3_cdn_url
|
||||||
# when using s3, we need to replace with the absolute base url
|
# when using s3, we need to replace with the absolute base url
|
||||||
url = url.sub(SiteSetting.Upload.s3_cdn_url, Discourse.store.absolute_base_url) if SiteSetting.Upload.s3_cdn_url.present?
|
url = url.sub(SiteSetting.Upload.s3_cdn_url, Discourse.store.absolute_base_url) if SiteSetting.Upload.s3_cdn_url.present?
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,22 @@ describe Upload do
|
||||||
|
|
||||||
expect(Upload.get_from_url(URI.join(s3_cdn_url, path).to_s)).to eq(upload)
|
expect(Upload.get_from_url(URI.join(s3_cdn_url, path).to_s)).to eq(upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return the right upload when using one CDN for both s3 and assets" do
|
||||||
|
begin
|
||||||
|
original_asset_host = Rails.configuration.action_controller.asset_host
|
||||||
|
cdn_url = 'http://my.cdn.com'
|
||||||
|
Rails.configuration.action_controller.asset_host = cdn_url
|
||||||
|
SiteSetting.s3_cdn_url = cdn_url
|
||||||
|
upload
|
||||||
|
|
||||||
|
expect(Upload.get_from_url(
|
||||||
|
URI.join(cdn_url, path).to_s
|
||||||
|
)).to eq(upload)
|
||||||
|
ensure
|
||||||
|
Rails.configuration.action_controller.asset_host = original_asset_host
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue