2020-12-07 16:21:46 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
# Recibe notificaciones desde Airbrake
|
|
|
|
class NoticesController < BaseController
|
|
|
|
skip_before_action :verify_authenticity_token
|
|
|
|
|
|
|
|
# Generar un stacktrace en segundo plano y enviarlo por correo
|
|
|
|
# solo si la API key es verificable. Del otro lado siempre
|
|
|
|
# respondemos con lo mismo.
|
2023-09-22 16:51:36 +00:00
|
|
|
def create
|
2023-09-22 18:10:46 +00:00
|
|
|
if (site&.airbrake_valid? airbrake_token) && !detected_device.bot?
|
2020-12-07 16:21:46 +00:00
|
|
|
BacktraceJob.perform_later site_id: params[:site_id],
|
2023-09-22 16:51:36 +00:00
|
|
|
params: airbrake_params.to_h
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
2023-01-12 16:40:43 +00:00
|
|
|
render status: 201, json: { id: 1, url: '' }
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# XXX: Por alguna razón Airbrake envía los datos con Content-Type:
|
|
|
|
# text/plain.
|
|
|
|
def airbrake_params
|
2020-12-07 18:27:24 +00:00
|
|
|
@airbrake_params ||= params.merge!(FastJsonparser.parse(request.raw_post) || {}).permit!
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def site
|
|
|
|
@site ||= Site.find(params[:site_id])
|
2020-12-08 21:51:41 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def airbrake_token
|
|
|
|
@airbrake_token ||= params[:key]
|
|
|
|
end
|
2023-09-22 16:51:36 +00:00
|
|
|
|
|
|
|
# @return [DeviceDetector]
|
|
|
|
def detected_device
|
2023-09-22 18:10:46 +00:00
|
|
|
@detected_device ||= DeviceDetector.new(request.headers['User-Agent'], request.headers)
|
2023-09-22 16:51:36 +00:00
|
|
|
end
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|