Implement track/stream
* Add Streamer class * Use FactoryGirl for factories * Add sha256 field to tracks * Add mime_type field to tracks
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
class Track < ActiveRecord::Base
|
||||
validates_presence_of :name
|
||||
validates_presence_of :mime_type
|
||||
validates_presence_of :sha256
|
||||
|
||||
after_create :save_file
|
||||
|
||||
def uploaded_file=(file)
|
||||
@file = file
|
||||
def filepath
|
||||
"#{Rails.root}/data/tracks/#{sha256}"
|
||||
end
|
||||
|
||||
def save_file
|
||||
if @file
|
||||
File.open("#{Rails.root}/data/tracks/#{id}", 'w') do |f|
|
||||
f.write @file.tempfile.read
|
||||
end
|
||||
def save_with_file(file, mime_type)
|
||||
self.sha256 = Digest::SHA256.file(file.path).hexdigest
|
||||
self.mime_type = mime_type
|
||||
File.open(filepath, 'w') do |f|
|
||||
f.write file.read
|
||||
end
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user