2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-09 11:04:34 -07:00
|
|
|
require 'singleton'
|
|
|
|
|
|
|
|
class TagManager
|
|
|
|
include Singleton
|
|
|
|
include RoutingHelper
|
|
|
|
|
2017-04-14 17:15:46 -07:00
|
|
|
def web_domain?(domain)
|
2023-09-19 07:53:58 -07:00
|
|
|
domain.nil? || domain.delete_suffix('/').casecmp(Rails.configuration.x.web_domain).zero?
|
2017-04-14 17:15:46 -07:00
|
|
|
end
|
|
|
|
|
2016-10-06 07:36:16 -07:00
|
|
|
def local_domain?(domain)
|
2023-09-19 07:53:58 -07:00
|
|
|
domain.nil? || domain.delete_suffix('/').casecmp(Rails.configuration.x.local_domain).zero?
|
2016-10-06 07:36:16 -07:00
|
|
|
end
|
|
|
|
|
2017-04-24 17:47:31 -07:00
|
|
|
def normalize_domain(domain)
|
2017-05-04 17:23:01 -07:00
|
|
|
return if domain.nil?
|
|
|
|
|
2017-04-24 17:47:31 -07:00
|
|
|
uri = Addressable::URI.new
|
2023-09-19 07:53:58 -07:00
|
|
|
uri.host = domain.delete_suffix('/')
|
2017-07-15 08:24:35 -07:00
|
|
|
uri.normalized_host
|
2017-04-24 17:47:31 -07:00
|
|
|
end
|
|
|
|
|
2017-01-27 07:55:06 -08:00
|
|
|
def local_url?(url)
|
2017-04-24 17:47:31 -07:00
|
|
|
uri = Addressable::URI.parse(url).normalize
|
2022-05-31 09:25:24 -07:00
|
|
|
return false unless uri.host
|
2023-02-19 21:58:28 -08:00
|
|
|
|
2017-01-27 07:55:06 -08:00
|
|
|
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
2019-07-08 18:27:35 -07:00
|
|
|
|
2017-09-13 05:22:16 -07:00
|
|
|
TagManager.instance.web_domain?(domain)
|
2023-09-06 03:17:51 -07:00
|
|
|
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
2022-05-31 09:25:24 -07:00
|
|
|
false
|
2017-01-27 07:55:06 -08:00
|
|
|
end
|
2016-09-09 11:04:34 -07:00
|
|
|
end
|