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,7 +30,8 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
urls << url.sub(/\?.*$/, '') if url.include?('?')
|
||||
|
||||
# add a cdn link
|
||||
if uri && Discourse.asset_host.present?
|
||||
if uri
|
||||
if Discourse.asset_host.present?
|
||||
cdn_uri = URI.parse(Discourse.asset_host) rescue nil
|
||||
if cdn_uri && cdn_uri.hostname == uri.hostname && uri.path.starts_with?(cdn_uri.path)
|
||||
is_cdn_link = true
|
||||
@ -38,6 +39,18 @@ class TopicLinkClick < ActiveRecord::Base
|
||||
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
|
||||
|
||||
link = TopicLink.select([:id, :user_id])
|
||||
|
||||
# test for all possible URLs
|
||||
|
@ -144,6 +144,24 @@ describe TopicLinkClick do
|
||||
|
||||
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
|
||||
|
||||
context 'with a HTTPS version of the same URL' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user