mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 14:49:07 +08:00
BUGFIX: make sure we do not try to pull images from the CDN
This commit is contained in:
parent
21e8ae0eca
commit
4b9acd6806
|
@ -94,9 +94,21 @@ module Jobs
|
|||
end
|
||||
|
||||
def is_valid_image_url(src)
|
||||
src.present? &&
|
||||
!Discourse.store.has_been_uploaded?(src) &&
|
||||
!src.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix) &&
|
||||
# make sure we actually have a url
|
||||
return false unless src.present?
|
||||
# we don't want to pull uploaded images
|
||||
return false if Discourse.store.has_been_uploaded?(src)
|
||||
# parse the src
|
||||
begin
|
||||
uri = URI.parse(src)
|
||||
rescue URI::InvalidURIError
|
||||
return false
|
||||
end
|
||||
# we don't want to pull images hosted on the CDN (if we use one)
|
||||
return false if Discourse.asset_host.present? && URI.parse(Discourse.asset_host).hostname == uri.hostname
|
||||
# we don't want to pull images hosted on the main domain
|
||||
return false if URI.parse(Discourse.base_url_no_prefix).hostname == uri.hostname
|
||||
# check the domains blacklist
|
||||
SiteSetting.should_download_images?(src)
|
||||
end
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ class SiteSetting < ActiveRecord::Base
|
|||
def self.should_download_images?(src)
|
||||
setting = disabled_image_download_domains
|
||||
return true unless setting.present?
|
||||
host = URI.parse(src).host
|
||||
|
||||
host = URI.parse(src).host
|
||||
return !(setting.split('|').include?(host))
|
||||
rescue URI::InvalidURIError
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue
Block a user