e2a2bc9021
Conflicts: - `README.md`: Upstream updated copyright year, we don't mention it so kept our version. - `app/controllers/admin/dashboard_controller.rb`: Not really a conflict, upstream change (removing the spam checker) too close to glitch-soc changes. Ported upstream changes. - `app/models/form/admin_settings.rb`: Same. - `app/services/remove_status_service.rb`: Same. - `app/views/admin/settings/edit.html.haml`: Same. - `config/settings.yml`: Same. - `config/environments/production.rb`: Not a real conflict, upstream added a default HTTP header, but we have extra headers in glitch-soc. Added the header.
34 lines
796 B
Ruby
34 lines
796 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'singleton'
|
|
|
|
class TagManager
|
|
include Singleton
|
|
include RoutingHelper
|
|
|
|
def web_domain?(domain)
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
|
|
end
|
|
|
|
def local_domain?(domain)
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
|
end
|
|
|
|
def normalize_domain(domain)
|
|
return if domain.nil?
|
|
|
|
uri = Addressable::URI.new
|
|
uri.host = domain.gsub(/[\/]/, '')
|
|
uri.normalized_host
|
|
end
|
|
|
|
def local_url?(url)
|
|
uri = Addressable::URI.parse(url).normalize
|
|
return false unless uri.host
|
|
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
|
|
|
TagManager.instance.web_domain?(domain)
|
|
rescue Addressable::URI::InvalidURIError
|
|
false
|
|
end
|
|
end
|