2011-10-12 09:24:07 +00:00
|
|
|
class TrackController < ApplicationController
|
|
|
|
before_filter :authorize
|
|
|
|
|
|
|
|
def update_length
|
|
|
|
unless params[:track_id].nil?
|
|
|
|
track = Track.find(params[:track_id])
|
|
|
|
unless track.nil? or params[:length].nil?
|
|
|
|
if track.length == nil or track.length.to_i == 0 and params[:length].to_i > 0
|
|
|
|
track.length = params[:length].to_i
|
|
|
|
track.save
|
2011-10-20 11:01:57 +00:00
|
|
|
return render :json => { :result => :success }
|
2011-10-12 09:24:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render :json => { :result => :failed }
|
|
|
|
end
|
2011-10-13 13:47:19 +00:00
|
|
|
|
|
|
|
def report_unavailable
|
|
|
|
track = Track.find(params[:id])
|
|
|
|
unless track.nil? or track.available
|
|
|
|
track.available = true
|
|
|
|
track.save
|
2011-10-20 11:01:57 +00:00
|
|
|
return render :json => { :status => :success }
|
2011-10-13 13:47:19 +00:00
|
|
|
end
|
|
|
|
render :json => { :status => :failed }
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_bad
|
|
|
|
track = Track.find(params[:id])
|
|
|
|
unless track.nil?
|
|
|
|
# Saving track file
|
|
|
|
vote(params[:track_id], params[:owner_id], params[:audio_id], -1)
|
2011-10-20 11:01:57 +00:00
|
|
|
return render :json => { :status => :success }
|
2011-10-13 13:47:19 +00:00
|
|
|
end
|
|
|
|
render :json => { :status => :failed }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def vote track_id, owner_id, audio_id, delta = 0
|
|
|
|
track_file = TrackFile.find_or_create_by_track_id_and_owner_id_and_audio_id(
|
|
|
|
track_id, owner_id, audio_id
|
|
|
|
){ |tf| tf.rating = 0 }
|
|
|
|
track_file.rating += delta
|
|
|
|
track_file.save
|
|
|
|
end
|
2011-10-12 09:24:07 +00:00
|
|
|
end
|