5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-17 04:46:22 +00:00

Merge branch 'sites-api' into 'rails'

devolver todos los dominios

See merge request sutty/sutty!80
This commit is contained in:
fauno 2023-03-23 21:51:33 +00:00
commit 41918bde6a

View file

@ -9,7 +9,7 @@ module Api
# Lista de nombres de dominios a emitir certificados
def index
render json: sites_names + alternative_names + api_names
render json: sites_names + alternative_names + api_names + www_names
end
# Sitios con hidden service de Tor
@ -28,7 +28,7 @@ module Api
site = Site.find_by(name: params[:name])
if site
usuarie = GitAuthor.new email: 'tor@' + Site.domain, name: 'Tor'
usuarie = GitAuthor.new email: "tor@#{Site.domain}", name: 'Tor'
service = SiteService.new site: site, usuarie: usuarie,
params: params
service.add_onion
@ -39,14 +39,22 @@ module Api
private
def canonicalize(name)
name.end_with?('.') ? name[0..-2] : "#{name}.#{Site.domain}"
end
# Nombres de los sitios
def sites_names
Site.all.order(:name).pluck(:name)
Site.all.order(:name).pluck(:name).map do |name|
canonicalize name
end
end
# Dominios alternativos
def alternative_names
DeployAlternativeDomain.all.map(&:hostname)
(DeployAlternativeDomain.all.map(&:hostname) + DeployLocalizedDomain.all.map(&:hostname)).map do |name|
canonicalize name
end
end
# Obtener todos los sitios con API habilitada, es decir formulario
@ -56,7 +64,16 @@ module Api
def api_names
Site.where(contact: true)
.or(Site.where(colaboracion_anonima: true))
.select("'api.' || name as name").map(&:name)
.select("'api.' || name as name").map(&:name).map do |name|
canonicalize name
end
end
# 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
end
end
end
end