mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +00:00
FIX: S3Cdn link clicks weren't working
This commit is contained in:
parent
76766a25bf
commit
61ce5c210c
@ -30,11 +30,24 @@ class TopicLinkClick < ActiveRecord::Base
|
|||||||
urls << url.sub(/\?.*$/, '') if url.include?('?')
|
urls << url.sub(/\?.*$/, '') if url.include?('?')
|
||||||
|
|
||||||
# add a cdn link
|
# add a cdn link
|
||||||
if uri && Discourse.asset_host.present?
|
if uri
|
||||||
cdn_uri = URI.parse(Discourse.asset_host) rescue nil
|
if Discourse.asset_host.present?
|
||||||
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
cdn_uri = URI.parse(Discourse.asset_host) rescue nil
|
||||||
is_cdn_link = true
|
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
||||||
urls << uri.path[(cdn_uri.path.length)..-1]
|
is_cdn_link = true
|
||||||
|
urls << uri.path[(cdn_uri.path.length)..-1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if SiteSetting.s3_cdn_url.present?
|
||||||
|
cdn_uri = URI.parse(SiteSetting.s3_cdn_url) rescue nil
|
||||||
|
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
||||||
|
is_cdn_link = true
|
||||||
|
|
||||||
|
path = uri.path[(cdn_uri.path.length)..-1]
|
||||||
|
urls << path
|
||||||
|
urls << "#{Discourse.store.absolute_base_url}#{path}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -144,6 +144,24 @@ describe TopicLinkClick do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "s3 cdns" do
|
||||||
|
|
||||||
|
it "works with s3 urls" do
|
||||||
|
SiteSetting.s3_cdn_url = "https://discourse-s3-cdn.global.ssl.fastly.net"
|
||||||
|
|
||||||
|
post = Fabricate(:post, topic: @topic, raw: "[test](//test.localhost/uploads/default/my-test-link)")
|
||||||
|
TopicLink.extract_from(post)
|
||||||
|
|
||||||
|
url = TopicLinkClick.create_from(
|
||||||
|
url: "https://discourse-s3-cdn.global.ssl.fastly.net/my-test-link",
|
||||||
|
topic_id: @topic.id,
|
||||||
|
ip: '127.0.0.3')
|
||||||
|
|
||||||
|
expect(url).to be_present
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a HTTPS version of the same URL' do
|
context 'with a HTTPS version of the same URL' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user