1 # frozen_string_literal: true
 
   5     class DataController < ApiController
 
   6       before_action :set_locale
 
   7       before_action :authorize
 
   9       authorize_resource :trace
 
  11       before_action :offline_error
 
  14         trace = Trace.visible.find(params[:trace_id])
 
  16         if trace.public? || trace.user == current_user
 
  17           if request.format == Mime[:xml]
 
  18             send_data(trace.xml_file.read, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
 
  19           elsif request.format == Mime[:gpx]
 
  20             send_data(trace.xml_file.read, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => "attachment")
 
  21           elsif trace.file.attached?
 
  22             redirect_to rails_blob_path(trace.file, :disposition => "attachment")
 
  24             send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
 
  34         report_error "GPX files offline for maintenance", :service_unavailable if Settings.status == "gpx_offline"