mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-28 15:16:22 +00:00
82 lines
1.8 KiB
Ruby
82 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Controlador de sitios
|
|
class SitesController < ApplicationController
|
|
include Pundit
|
|
before_action :authenticate_usuarie!
|
|
|
|
# Ver un listado de sitios
|
|
def index
|
|
authorize Site
|
|
@sites = current_usuarie.sites
|
|
end
|
|
|
|
# No tenemos propiedades de un sitio aún, así que vamos al listado de
|
|
# artículos
|
|
def show
|
|
authorize Site
|
|
site = find_site
|
|
|
|
redirect_to site_posts_path(site)
|
|
end
|
|
|
|
# Envía un archivo del directorio público de Jekyll
|
|
def send_public_file
|
|
authorize Site
|
|
@site = find_site
|
|
file = [params[:basename], params[:format]].join('.')
|
|
path = File.join(@site.path, 'public', params[:type], file)
|
|
path = Pathname.new path
|
|
|
|
# TODO: Verificar que no nos estén sacando archivos del sistema, como
|
|
# /etc/passwd
|
|
#
|
|
# En sí el matcher de la ruta no admite .. así que estaríamos semi
|
|
# cubiertas.
|
|
|
|
if path.exist?
|
|
send_file path, 'x-sendfile': true
|
|
else
|
|
render status: 404
|
|
end
|
|
end
|
|
|
|
def enqueue
|
|
@site = find_site
|
|
authorize @site
|
|
@site.enqueue!
|
|
|
|
redirect_to sites_path
|
|
end
|
|
|
|
def build_log
|
|
@site = find_site
|
|
authorize @site
|
|
|
|
# TODO: eliminar ANSI
|
|
render file: @site.build_log,
|
|
layout: false,
|
|
content_type: 'text/plain; charset=utf-8'
|
|
end
|
|
|
|
def reorder_posts
|
|
@site = find_site
|
|
authorize @site
|
|
lang = params.require(:posts).require(:lang)
|
|
|
|
if params[:posts][:force].present?
|
|
result = @site.reorder_collection! lang
|
|
else
|
|
result = @site
|
|
.reorder_collection(lang, params.require(:posts).require(:order))
|
|
end
|
|
|
|
if result
|
|
flash[:info] = I18n.t('info.posts.reorder')
|
|
else
|
|
flash[:danger] = I18n.t('errors.posts.reorder')
|
|
end
|
|
|
|
redirect_to site_posts_path @site
|
|
end
|
|
end
|