X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/7eec8de2a694764831ed26936f09aefec50ed9f4..9ec1b1bea5fc3aff0b159518f75375f878e24410:/app/controllers/trace_controller.rb diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 478109eb0..c5552f39d 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -7,6 +7,8 @@ class TraceController < ApplicationController # target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces # paging_action - the action that will be linked back to from view def list (target_user = nil, paging_action = 'list') + @title = 'public GPS traces' + @title += " tagged with #{params[:tag]}" if params[:tag] @traces_per_page = 20 page_index = params[:page] ? params[:page].to_i - 1 : 0 # nice 1-based page -> 0-based page index @@ -15,6 +17,7 @@ class TraceController < ApplicationController if target_user.nil? and display_name and display_name != '' @paging_action = 'view' @display_name = display_name + @title += " from #{@display_name}" target_user = User.find(:first, :conditions => [ "display_name = ?", display_name]) end @@ -120,8 +123,10 @@ class TraceController < ApplicationController def data trace = Trace.find(params[:id]) - if trace.public? or (@user and @user == trace.user) - send_data(File.open("/home/osm/gpx/#{trace.id}.gpx",'r').read , :filename => "#{trace.id}.gpx", :type => 'text/plain', :disposition => 'inline') + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.trace_name, :filename => "#{trace.id}.gpx", :type => trace.mime_type, :disposition => 'attachment') + else + render :nothing, :status => 404 end end @@ -152,12 +157,20 @@ class TraceController < ApplicationController def picture trace = Trace.find(params[:id]) - send_data(trace.large_picture, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user) + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => 404 + end end def icon trace = Trace.find(params[:id]) - send_data(trace.icon_picture, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') if trace.public? or (@user and @user == trace.user) + if trace and (trace.public? or (@user and @user == trace.user)) + send_file(trace.icon_picture_name, :filename => "#{trace.id}_icon.gif", :type => 'image/gif', :disposition => 'inline') + else + render :nothing, :status => 404 + end end def api_details