jam-cloud/web/app/controllers/api_jam_tracks_controller.rb

43 lines
1.4 KiB
Ruby

class ApiJamTracksController < ApiController
# have to be signed in currently to see this screen
before_filter :api_signed_in_user
before_filter :lookup_jam_track, :only => [ :download ]
respond_to :json
def list_downloads
begin
render :json => JamTrack.list_downloads(current_user, params[:limit], params[:since]), :status => 200
rescue
render :json => { :message => "could not produce list of files" }, :status => 403
end
end
def download
if @jam_track_right.valid?
puts "Success"
if (@jam_track_right && @jam_track_right.signed && @jam_track_right.url.present? &&@jam_track_right.url.file.exists?)
@jam_track_right.update_download_count
@jam_track_right.save!
redirect_to @jam_track_right.sign_url
else
@jam_track_right.enqueue
render :json => { :message => "not available, digitally signing Jam Track offline." }, :status => 202
end
else
puts "#@jam_track_right.errors: #{@jam_track_right.errors.inspect}"
render :json => { :message => "download limit surpassed" }, :status => 403
end
end
private
def lookup_jam_track
@jam_track_right = JamTrackRight.where("jam_track_id=? AND user_id=?", params[:id], current_user).first
puts "@jam_track_right: #{@jam_track_right.nil?}"
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR unless @jam_track_right
end
end