mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-23 15:51:50 +00:00
fix: optimizar api de sitios #18074
This commit is contained in:
parent
d95ba3f4c0
commit
e0e01a5445
1 changed files with 16 additions and 8 deletions
|
@ -9,22 +9,30 @@ module Api
|
|||
|
||||
# Lista de nombres de dominios a emitir certificados
|
||||
def index
|
||||
render json: alternative_names + api_names + www_names
|
||||
render json: alternative_names.concat(api_names).concat(www_names)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# @param query [ActiveRecord::Relation]
|
||||
# @return [Array<String>]
|
||||
def hostname_of(query)
|
||||
query.pluck(Arel.sql("values->>'hostname'")).compact.uniq
|
||||
end
|
||||
|
||||
def canonicalize(name)
|
||||
name.end_with?('.') ? name[0..-2] : "#{name}.#{Site.domain}"
|
||||
end
|
||||
|
||||
def subdomain?(name)
|
||||
name.end_with? ".#{Site.domain}"
|
||||
@@subdomain ||= ".#{Site.domain}"
|
||||
|
||||
name.end_with? @subdomain
|
||||
end
|
||||
|
||||
# Dominios alternativos
|
||||
def alternative_names
|
||||
(DeployAlternativeDomain.all.map(&:hostname) + DeployLocalizedDomain.all.map(&:hostname)).map do |name|
|
||||
hostname_of(DeployAlternativeDomain.all).concat(hostname_of(DeployLocalizedDomain)).map do |name|
|
||||
canonicalize name
|
||||
end.reject do |name|
|
||||
subdomain? name
|
||||
|
@ -33,12 +41,12 @@ module Api
|
|||
|
||||
# Obtener todos los sitios con API habilitada, es decir formulario
|
||||
# de contacto y/o colaboración anónima.
|
||||
#
|
||||
# TODO: Optimizar
|
||||
def api_names
|
||||
Site.where(contact: true)
|
||||
.or(Site.where(colaboracion_anonima: true))
|
||||
.select("'api.' || name as name").map(&:name).map do |name|
|
||||
.pluck(:name).map do |name|
|
||||
"api.#{name}"
|
||||
end.map do |name|
|
||||
canonicalize name
|
||||
end.reject do |name|
|
||||
subdomain? name
|
||||
|
@ -47,8 +55,8 @@ module Api
|
|||
|
||||
# Todos los dominios con WWW habilitado
|
||||
def www_names
|
||||
Site.where(id: DeployWww.all.pluck(:site_id)).select("'www.' || name as name").map(&:name).map do |name|
|
||||
canonicalize name
|
||||
Site.where(id: DeployWww.all.pluck(:site_id)).pluck(:name).map do |name|
|
||||
canonicalize "www.#{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue