mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
DEV: skip S3 CDN urls with different path in prefix. (#14488)
Previously, while retrieving each upload urls in a post S3 CDN urls with different path in prefix (external urls technically) are considered as uploaded url. It created issue while checking missing uploads.
This commit is contained in:
parent
f38fd1a5a7
commit
c8d5c049eb
|
@ -158,8 +158,11 @@ module FileStore
|
|||
end
|
||||
|
||||
return false if SiteSetting.Upload.s3_cdn_url.blank?
|
||||
cdn_hostname = URI.parse(SiteSetting.Upload.s3_cdn_url || "").hostname
|
||||
return true if cdn_hostname.presence && url[cdn_hostname]
|
||||
|
||||
s3_cdn_url = URI.parse(SiteSetting.Upload.s3_cdn_url || "")
|
||||
cdn_hostname = s3_cdn_url.hostname
|
||||
|
||||
return true if cdn_hostname.presence && url[cdn_hostname] && (s3_cdn_url.path.blank? || parsed_url.path.starts_with?(s3_cdn_url.path))
|
||||
false
|
||||
end
|
||||
|
||||
|
|
|
@ -1715,6 +1715,17 @@ describe Post do
|
|||
post.each_upload_url { |src, _, _| urls << src }
|
||||
expect(urls).to be_empty
|
||||
end
|
||||
|
||||
it "skip S3 cdn urls with different path" do
|
||||
setup_s3
|
||||
SiteSetting.Upload.stubs(:s3_cdn_url).returns("https://cdn.example.com/site1")
|
||||
|
||||
urls = []
|
||||
raw = "<img src='https://cdn.example.com/site1/original/1X/bc68acbc8c022726e69f980e00d6811212r.jpg' /><img src='https://cdn.example.com/site2/original/1X/bc68acbc8c022726e69f980e00d68112128.jpg' />"
|
||||
post = Fabricate(:post, raw: raw)
|
||||
post.each_upload_url { |src, _, _| urls << src }
|
||||
expect(urls).to contain_exactly("https://cdn.example.com/site1/original/1X/bc68acbc8c022726e69f980e00d6811212r.jpg")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#publish_changes_to_client!" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user