aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/import_task.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/import_task.rb')
-rw-r--r--app/models/import_task.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/app/models/import_task.rb b/app/models/import_task.rb
index 760080c25..0e1ab65be 100644
--- a/app/models/import_task.rb
+++ b/app/models/import_task.rb
@@ -20,7 +20,7 @@ class ImportTask
validates_presence_of :user_name
validates_presence_of :name
- validate :validate_file_size
+ validate :validate_file_size, :validate_file_content
def initialize( params = {} )
params.each {|k,v| send("#{k}=",v)}
@@ -133,4 +133,23 @@ class ImportTask
end
end
+ @@valid_mime_types = {
+ neptune: %w{application/zip application/xml},
+ netex: %w{application/zip},
+ gtfs: %w{application/zip text/plain}
+ }
+ cattr_accessor :valid_mime_types
+
+ def validate_file_content
+ return unless resources.present? and resources.path.present? and File.exists? resources.path
+
+ mime_type = (File.open(resources.path) { |f| MimeMagic.by_magic f }).try :type
+ expected_mime_types = valid_mime_types[data_format.to_sym]
+
+ unless expected_mime_types.include? mime_type
+ message = I18n.t("activemodel.errors.models.import_task.attributes.resources.invalid_mime_type", mime_type: mime_type)
+ errors.add(:resources, message)
+ end
+ end
+
end