1
0
Fork 0
oldhaven/app/controllers/track_controller.rb

47 lines
1.3 KiB
Ruby

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
return render :json => { :result => :success }
end
end
end
render :json => { :result => :failed }
end
def report_unavailable
track = Track.find(params[:id])
unless track.nil? or track.available
track.available = false
track.save
return render :json => { :status => :success }
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)
return render :json => { :status => :success }
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
end