Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop

This commit is contained in:
Seth Call 2015-12-04 09:29:04 -06:00
commit 8e72a9833a
5 changed files with 62 additions and 6 deletions

View File

@ -528,6 +528,28 @@ module JamRuby
"#{self.name} (#{self.original_artist})"
end
def self.latestPurchase(user_id)
jtx_created = JamTrackRight
.select('created_at')
.where(user_id: user_id)
.order('created_at DESC')
.limit(1)
jtx_created.first.created_at.to_i
end
def self.mixdownChecksum(user_id, jam_track_id)
dates = JamTrackMixdown
.select('created_at')
.where(user_id: user_id, jam_track_id: jam_track_id)
.order(:id)
dates = dates.map do |date|
date.created_at.to_i.to_s
end.join('')
Digest::MD5.hexdigest(dates)
end
attr_accessor :preview_generate_error
before_save :jmep_json_generate

View File

@ -97,8 +97,40 @@ class ApiJamTracksController < ApiController
end
end
def _handlePurchasedHead
if jtid = params[:id]
if params[:mixcheck]
checksum = JamTrack.mixdownChecksum(current_user.id, jtid)
head :ok, checksum: checksum
return
else
# if the requested jamtrack is not purchased, send status code 204
if 0 == JamTrack.where(id: jtid, user_id: current_user.id).count
head(:no_content)
return
end
end
elsif params[:syncbuys]
syncbuys = params[:syncbuys].to_i
latestPurchase = JamTrack.latestPurchase(current_user.id)
if 0 == syncbuys || (0 < latestPurchase && (latestPurchase <= syncbuys))
head :no_content, latestpurchase: latestPurchase
return
else
head :ok, latestpurchase: latestPurchase
return
end
end
head(:ok)
end
def purchased
params[:show_purchased_only] = true
if request.head?
self._handlePurchasedHead
return
end
params[:show_purchased_only] = true
data = JamTrack.index(params, current_user)
@jam_tracks, @next = data[0], data[1]

View File

@ -78,7 +78,7 @@ ApiUsersController < ApiController
email: params[:email],
password: params[:password],
password_confirmation: params[:password],
terms_of_service: params[:terms],
terms_of_service: params[:terms_of_service].to_i,
location: {:country => nil, :state => nil, :city => nil},
signup_hint: signup_hint,
gift_card: params[:gift_card],

View File

@ -2,6 +2,10 @@ object @jam_track_mixdown
attributes :id, :name, :description, :jam_track_id
node :created_at do |item|
item.created_at.to_i
end
node :settings do |item|
JSON.parse(item.settings)
end

View File

@ -10,10 +10,6 @@ node :jmep do |jam_track|
jam_track.jmep_json ? JSON.parse(jam_track.jmep_json) : nil
end
node :jam_track_right_id do |jam_track|
jam_track.right_for_user(current_user).id
end
child(:jam_track_tracks => :tracks) {
attributes :id, :part, :instrument, :track_type, :position
@ -29,6 +25,8 @@ child(:jam_track_tracks => :tracks) {
node do |jam_track|
right = jam_track.right_for_user(current_user)
{
jam_track_right_id: right.id,
purchased_at: right.created_at.to_i,
last_mixdown_id: right.last_mixdown_id,
last_stem_id: right.last_stem_id
}