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