2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-09 15:24:16 -04:00
|
|
|
module GlobalPath
|
|
|
|
def path(p)
|
|
|
|
"#{GlobalSetting.relative_url_root}#{p}"
|
|
|
|
end
|
2015-05-26 01:41:50 -04:00
|
|
|
|
|
|
|
def cdn_path(p)
|
2018-11-23 10:11:05 -05:00
|
|
|
GlobalSetting.cdn_url.blank? ? p : "#{GlobalSetting.cdn_url}#{path(p)}"
|
2015-05-26 01:41:50 -04:00
|
|
|
end
|
2016-02-04 21:05:47 -05:00
|
|
|
|
2017-05-08 11:38:48 -04:00
|
|
|
def upload_cdn_path(p)
|
2017-10-06 01:20:01 -04:00
|
|
|
if SiteSetting.Upload.s3_cdn_url.present?
|
2018-10-24 00:14:01 -04:00
|
|
|
p = Discourse.store.cdn_url(p)
|
2017-05-08 11:38:48 -04:00
|
|
|
end
|
2019-01-03 18:50:35 -05:00
|
|
|
|
|
|
|
(p =~ /^http/ || p =~ /^\/\//) ? p : cdn_path(p)
|
2017-05-08 11:38:48 -04:00
|
|
|
end
|
|
|
|
|
2016-02-04 21:05:47 -05:00
|
|
|
def cdn_relative_path(path)
|
|
|
|
if (cdn_url = GlobalSetting.cdn_url).present?
|
|
|
|
URI.parse(cdn_url).path + path
|
|
|
|
else
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-19 04:20:48 -05:00
|
|
|
def full_cdn_url(url)
|
|
|
|
uri = URI.parse(UrlHelper.absolute(upload_cdn_path(url)))
|
|
|
|
uri.scheme = SiteSetting.scheme if uri.scheme.blank?
|
|
|
|
uri.to_s
|
|
|
|
end
|
|
|
|
|
2015-03-09 15:24:16 -04:00
|
|
|
end
|