]> git.openstreetmap.org Git - rails.git/commitdiff
Provide a more sensible suggested filename when downloading traces.
authorTom Hughes <tom@compton.nu>
Tue, 17 Jul 2007 14:34:22 +0000 (14:34 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 17 Jul 2007 14:34:22 +0000 (14:34 +0000)
app/controllers/trace_controller.rb
app/models/trace.rb

index 5b1702948185a304ad31358d5d0ab9535e378264..288a4a67b676d6002f50fd1ea638ea68e5dc52b8 100644 (file)
@@ -118,7 +118,7 @@ class TraceController < ApplicationController
   def data
     trace = Trace.find(params[:id])
     if trace and (trace.public? or (@user and @user == trace.user))
   def data
     trace = Trace.find(params[:id])
     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')
+      send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment')
     else
       render :nothing, :status => :not_found
     end
     else
       render :nothing, :status => :not_found
     end
index 92cc39678d767b32e209d96a86fd254063be75af..7097e0973fc958b3e416ea1cbe1f8cb59331990c 100644 (file)
@@ -76,6 +76,32 @@ class Trace < ActiveRecord::Base
     return `file -bi #{trace_name}`.chomp
   end
 
     return `file -bi #{trace_name}`.chomp
   end
 
+  def extension_name
+    filetype = `file -bz #{trace_name}`.chomp
+    gzipped = filetype =~ /gzip compressed/
+    bzipped = filetype =~ /bzip2 compressed/
+    zipped = filetype =~ /Zip archive/
+    tarred = filetype =~ /tar archive/
+
+    if tarred and gzipped then
+      extension = ".tar.gz"
+    elsif tarred and bzipped then
+      extension = ".tar.bz2"
+    elsif tarred
+      extension = ".tar"
+    elsif gzipped
+      extension = ".gpx.gz"
+    elsif bzipped
+      extension = ".gpx.bz2"
+    elsif zipped
+      extension = ".zip"
+    else
+      extension = ".gpx"
+    end
+
+    return extension
+  end
+
   def to_xml
     doc = OSM::API.new.get_xml_doc
     doc.root << to_xml_node()
   def to_xml
     doc = OSM::API.new.get_xml_doc
     doc.root << to_xml_node()