1 # frozen_string_literal: true
 
   4   class DataController < ApplicationController
 
   7     before_action :authorize_web
 
   8     before_action :set_locale
 
   9     before_action :check_database_readable
 
  11     authorize_resource :class => Trace
 
  13     before_action :offline_redirect
 
  16       trace = Trace.visible.find(params[:trace_id])
 
  18       if trace.public? || (current_user && current_user == trace.user)
 
  19         if Acl.no_trace_download?(request.remote_ip)
 
  21         elsif request.format == Mime[:xml]
 
  22           send_data(trace.xml_file.read, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
 
  23         elsif request.format == Mime[:gpx]
 
  24           send_data(trace.xml_file.read, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => "attachment")
 
  25         elsif trace.file.attached?
 
  26           redirect_to rails_blob_path(trace.file, :disposition => "attachment")
 
  28           send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
 
  33     rescue ActiveRecord::RecordNotFound
 
  40       render :template => "traces/offline" if Settings.status == "gpx_offline"