DEV: `InlineUploads` should process CDN upload URLs as well.
This commit is contained in:
parent
a01488ae67
commit
befb074c98
|
@ -128,7 +128,11 @@ class InlineUploads
|
|||
end
|
||||
|
||||
if !Discourse.store.external?
|
||||
next if uri&.host && uri.host != Discourse.current_hostname
|
||||
host = uri&.host
|
||||
|
||||
if host && ![Discourse.current_hostname, URI(GlobalSetting.cdn_url).hostname].include?(host)
|
||||
next
|
||||
end
|
||||
end
|
||||
|
||||
upload = Upload.get_from_url(link)
|
||||
|
@ -242,6 +246,7 @@ class InlineUploads
|
|||
matches = []
|
||||
|
||||
base_url = Discourse.base_url.sub(/https?:\/\//, "(https?://)")
|
||||
cdn_url = GlobalSetting.cdn_url.sub(/https?:\/\//, "(https?://)")
|
||||
|
||||
regexps = [
|
||||
/(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
|
||||
|
@ -260,10 +265,12 @@ class InlineUploads
|
|||
regexps << /(#{SiteSetting.Upload.s3_cdn_url}#{UPLOAD_REGEXP_PATTERN})/
|
||||
regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
regexps << /(#{cdn_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
end
|
||||
else
|
||||
regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
regexps << /(#{cdn_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
|
||||
end
|
||||
|
||||
node = node.to_s
|
||||
|
|
|
@ -3,12 +3,7 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe InlineUploads do
|
||||
before do
|
||||
@original_asset_host = Rails.configuration.action_controller.asset_host
|
||||
Rails.configuration.action_controller.asset_host = "https://cdn.discourse.org/stuff"
|
||||
end
|
||||
|
||||
after do
|
||||
Rails.configuration.action_controller.asset_host = @original_asset_host
|
||||
set_cdn_url "https://awesome.com"
|
||||
end
|
||||
|
||||
describe '.process' do
|
||||
|
@ -214,6 +209,8 @@ RSpec.describe InlineUploads do
|
|||
#{Discourse.base_url}#{upload.url} #{Discourse.base_url}#{upload2.url}
|
||||
|
||||
#{Discourse.base_url}#{upload3.url}
|
||||
|
||||
#{GlobalSetting.cdn_url}#{upload3.url}
|
||||
MD
|
||||
|
||||
expect(InlineUploads.process(md)).to eq(<<~MD)
|
||||
|
@ -221,6 +218,8 @@ RSpec.describe InlineUploads do
|
|||
|
||||
#{Discourse.base_url}#{upload.short_path} #{Discourse.base_url}#{upload2.short_path}
|
||||
|
||||
![](#{upload3.short_url})
|
||||
|
||||
![](#{upload3.short_url})
|
||||
MD
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue