]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/trace.rb
Make the search URLs include a marker.
[rails.git] / app / models / trace.rb
index 7097e0973fc958b3e416ea1cbe1f8cb59331990c..c189c035ec8fb3e4812c52d2d07d659c9a615b92 100644 (file)
@@ -73,11 +73,26 @@ class Trace < ActiveRecord::Base
   end
 
   def mime_type
   end
 
   def mime_type
-    return `file -bi #{trace_name}`.chomp
+    filetype = `/usr/bin/file -bz #{trace_name}`.chomp
+    gzipped = filetype =~ /gzip compressed/
+    bzipped = filetype =~ /bzip2 compressed/
+    zipped = filetype =~ /Zip archive/
+
+    if gzipped then
+      mimetype = "application/x-gzip"
+    elsif bzipped then
+      mimetype = "application/x-bzip2"
+    elsif zipped
+      mimetype = "application/x-zip"
+    else
+      mimetype = "text/xml"
+    end
+
+    return mimetype
   end
 
   def extension_name
   end
 
   def extension_name
-    filetype = `file -bz #{trace_name}`.chomp
+    filetype = `/usr/bin/file -bz #{trace_name}`.chomp
     gzipped = filetype =~ /gzip compressed/
     bzipped = filetype =~ /bzip2 compressed/
     zipped = filetype =~ /Zip archive/
     gzipped = filetype =~ /gzip compressed/
     bzipped = filetype =~ /bzip2 compressed/
     zipped = filetype =~ /Zip archive/
@@ -126,7 +141,7 @@ class Trace < ActiveRecord::Base
       logger.info("GPX Import importing #{name} (#{id}) from #{user.email}")
 
       # TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
       logger.info("GPX Import importing #{name} (#{id}) from #{user.email}")
 
       # TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
-      filetype = `file -bz #{trace_name}`.chomp
+      filetype = `/usr/bin/file -bz #{trace_name}`.chomp
       gzipped = filetype =~ /gzip compressed/
       bzipped = filetype =~ /bzip2 compressed/
       zipped = filetype =~ /Zip archive/
       gzipped = filetype =~ /gzip compressed/
       bzipped = filetype =~ /bzip2 compressed/
       zipped = filetype =~ /Zip archive/
@@ -173,7 +188,6 @@ class Trace < ActiveRecord::Base
         tp.lng = point['longitude'].to_f
         tp.altitude = point['altitude'].to_f
         tp.timestamp = point['timestamp']
         tp.lng = point['longitude'].to_f
         tp.altitude = point['altitude'].to_f
         tp.timestamp = point['timestamp']
-        tp.user_id = user.id
         tp.gpx_id = id
         tp.trackid = point['segment'].to_i
         tp.save!
         tp.gpx_id = id
         tp.trackid = point['segment'].to_i
         tp.save!
@@ -196,7 +210,7 @@ class Trace < ActiveRecord::Base
         self.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon)
         self.size = gpx.actual_points
         self.inserted = true
         self.icon_picture = gpx.get_icon(min_lat, min_lon, max_lat, max_lon)
         self.size = gpx.actual_points
         self.inserted = true
-        self.save
+        self.save!
       end
 
       logger.info "done trace #{id}"
       end
 
       logger.info "done trace #{id}"