Merge
This commit is contained in:
parent
aba4546e44
commit
2004d48fa1
|
|
@ -257,3 +257,4 @@ widen_user_authorization_token.sql
|
||||||
jam_track_version.sql
|
jam_track_version.sql
|
||||||
recorded_jam_track_tracks.sql
|
recorded_jam_track_tracks.sql
|
||||||
jam_track_jmep_data.sql
|
jam_track_jmep_data.sql
|
||||||
|
add_jam_track_bitrates.sql
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
ALTER TABLE jam_track_tracks RENAME COLUMN url TO url_48;
|
||||||
|
ALTER TABLE jam_track_tracks RENAME COLUMN md5 TO md5_48;
|
||||||
|
ALTER TABLE jam_track_tracks RENAME COLUMN length TO length_48;
|
||||||
|
ALTER TABLE jam_track_tracks ADD COLUMN url_44 VARCHAR;
|
||||||
|
ALTER TABLE jam_track_tracks ADD COLUMN md5_44 VARCHAR;
|
||||||
|
ALTER TABLE jam_track_tracks ADD COLUMN length_44 BIGINT;
|
||||||
|
|
||||||
|
ALTER TABLE jam_track_rights RENAME COLUMN url TO url_48;
|
||||||
|
ALTER TABLE jam_track_rights RENAME COLUMN md5 TO md5_48;
|
||||||
|
ALTER TABLE jam_track_rights RENAME COLUMN length TO length_48;
|
||||||
|
ALTER TABLE jam_track_rights ADD COLUMN url_44 VARCHAR;
|
||||||
|
ALTER TABLE jam_track_rights ADD COLUMN md5_44 VARCHAR;
|
||||||
|
ALTER TABLE jam_track_rights ADD COLUMN length_44 BIGINT;
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ module JamRuby
|
||||||
|
|
||||||
#raise ArgumentError, "output_jkz is empty #{output_jkz}" unless File.exists?(output_jkz)
|
#raise ArgumentError, "output_jkz is empty #{output_jkz}" unless File.exists?(output_jkz)
|
||||||
|
|
||||||
jam_track_right.url.store!(File.open(output_jkz, "rb"))
|
jam_track_right.url_48.store!(File.open(output_jkz, "rb"))
|
||||||
jam_track_right.signed=true
|
jam_track_right.signed=true
|
||||||
jam_track_right.downloaded_since_sign=false
|
jam_track_right.downloaded_since_sign=false
|
||||||
jam_track_right.private_key=File.read("#{tmp_dir}/skey.pem")
|
jam_track_right.private_key=File.read("#{tmp_dir}/skey.pem")
|
||||||
|
|
|
||||||
|
|
@ -129,9 +129,9 @@ module JamRuby
|
||||||
:type => "jam_track",
|
:type => "jam_track",
|
||||||
:id => jam_track_right.id.to_s,
|
:id => jam_track_right.id.to_s,
|
||||||
:jam_track_id => jam_track_right.jam_track_id,
|
:jam_track_id => jam_track_right.jam_track_id,
|
||||||
:length => jam_track_right.length,
|
:length => jam_track_right.length_48,
|
||||||
:md5 => jam_track_right.md5,
|
:md5 => jam_track_right.md5_48,
|
||||||
:url => jam_track_right.url,
|
:url => jam_track_right.url_48,
|
||||||
:created_at => jam_track_right.created_at,
|
:created_at => jam_track_right.created_at,
|
||||||
:next => jam_track_right.id
|
:next => jam_track_right.id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ module JamRuby
|
||||||
# describes what users have rights to which tracks
|
# describes what users have rights to which tracks
|
||||||
class JamTrackRight < ActiveRecord::Base
|
class JamTrackRight < ActiveRecord::Base
|
||||||
include JamRuby::S3ManagerMixin
|
include JamRuby::S3ManagerMixin
|
||||||
attr_accessible :user, :jam_track, :user_id, :jam_track_id, :url, :md5, :length, :download_count
|
attr_accessible :user, :jam_track, :user_id, :jam_track_id, :download_count
|
||||||
|
attr_accessible :user_id, :jam_track_id, as: :admin
|
||||||
|
attr_accessible :url_48, :md5_48, :length_48, :url_44, :md5_44, :length_44
|
||||||
belongs_to :user, class_name: "JamRuby::User" # the owner, or purchaser of the jam_track
|
belongs_to :user, class_name: "JamRuby::User" # the owner, or purchaser of the jam_track
|
||||||
belongs_to :jam_track, class_name: "JamRuby::JamTrack"
|
belongs_to :jam_track, class_name: "JamRuby::JamTrack"
|
||||||
|
|
||||||
|
|
@ -15,7 +17,8 @@ module JamRuby
|
||||||
validates_uniqueness_of :user_id, scope: :jam_track_id
|
validates_uniqueness_of :user_id, scope: :jam_track_id
|
||||||
|
|
||||||
# Uploads the JKZ:
|
# Uploads the JKZ:
|
||||||
mount_uploader :url, JamTrackRightUploader
|
mount_uploader :url_48, JamTrackRightUploader
|
||||||
|
mount_uploader :url_44, JamTrackRightUploader
|
||||||
before_destroy :delete_s3_files
|
before_destroy :delete_s3_files
|
||||||
|
|
||||||
MAX_JAM_TRACK_DOWNLOADS = 1000
|
MAX_JAM_TRACK_DOWNLOADS = 1000
|
||||||
|
|
@ -81,12 +84,13 @@ module JamRuby
|
||||||
# the idea is that this is used when a user who has the rights to this tries to download this JamTrack
|
# the idea is that this is used when a user who has the rights to this tries to download this JamTrack
|
||||||
# we would verify their rights (can_download?), and generates a URL in response to the click so that they can download
|
# we would verify their rights (can_download?), and generates a URL in response to the click so that they can download
|
||||||
# but the url is short lived enough so that it wouldn't be easily shared
|
# but the url is short lived enough so that it wouldn't be easily shared
|
||||||
def sign_url(expiration_time = 120)
|
def sign_url(expiration_time = 120, bitrate=48)
|
||||||
s3_manager.sign_url(self[:url], {:expires => expiration_time, :secure => false})
|
field_name = (bitrate==48) ? "url_48" : "url_44"
|
||||||
|
s3_manager.sign_url(self[field_name], {:expires => expiration_time, :secure => false})
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_s3_files
|
def delete_s3_files
|
||||||
remove_url!
|
remove_url_48!
|
||||||
end
|
end
|
||||||
|
|
||||||
def enqueue
|
def enqueue
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@ module JamRuby
|
||||||
# there should only be one Master per JamTrack, but there can be N Track per JamTrack
|
# there should only be one Master per JamTrack, but there can be N Track per JamTrack
|
||||||
TRACK_TYPE = %w{Track Master}
|
TRACK_TYPE = %w{Track Master}
|
||||||
|
|
||||||
mount_uploader :url, JamTrackTrackUploader
|
mount_uploader :url_48, JamTrackTrackUploader
|
||||||
|
mount_uploader :url_44, JamTrackTrackUploader
|
||||||
|
|
||||||
attr_accessible :jam_track_id, :track_type, :instrument, :instrument_id, :position, :part, :url, as: :admin
|
attr_accessible :jam_track_id, :track_type, :instrument, :instrument_id, :position, :part, as: :admin
|
||||||
|
attr_accessible :url_44, :url_48, :md5_44, :md5_48, :length_44, :length_48, as: :admin
|
||||||
|
|
||||||
validates :position, presence: true, numericality: {only_integer: true}, length: {in: 1..1000}
|
validates :position, presence: true, numericality: {only_integer: true}, length: {in: 1..1000}
|
||||||
validates :part, length: {maximum: 20}
|
validates :part, length: {maximum: 20}
|
||||||
|
|
@ -37,10 +39,11 @@ module JamRuby
|
||||||
# the idea is that this is used when a user who has the rights to this tries to download this JamTrack
|
# the idea is that this is used when a user who has the rights to this tries to download this JamTrack
|
||||||
# we would verify their rights (can_download?), and generates a URL in response to the click so that they can download
|
# we would verify their rights (can_download?), and generates a URL in response to the click so that they can download
|
||||||
# but the url is short lived enough so that it wouldn't be easily shared
|
# but the url is short lived enough so that it wouldn't be easily shared
|
||||||
def sign_url(expiration_time = 120)
|
def sign_url(expiration_time = 120, bitrate=48)
|
||||||
s3_manager.sign_url(self[:url], {:expires => expiration_time, :response_content_type => 'audio/ogg', :secure => false})
|
field_name = (bitrate==48) ? "url_48" : "url_44"
|
||||||
|
s3_manager.sign_url(self[field_name], {:expires => expiration_time, :response_content_type => 'audio/ogg', :secure => false})
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_download?(user)
|
def can_download?(user)
|
||||||
# I think we have to make a special case for 'previews', but maybe that's just up to the controller to not check can_download?
|
# I think we have to make a special case for 'previews', but maybe that's just up to the controller to not check can_download?
|
||||||
jam_track.owners.include?(user)
|
jam_track.owners.include?(user)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module JamRuby
|
||||||
|
|
||||||
JamRuby::JamTracksManager.save_jam_track_right_jkz(@jam_track_right)
|
JamRuby::JamTracksManager.save_jam_track_right_jkz(@jam_track_right)
|
||||||
|
|
||||||
length = @jam_track_right.url.size()
|
length = @jam_track_right.url_48.size()
|
||||||
md5 = Digest::MD5.new
|
md5 = Digest::MD5.new
|
||||||
|
|
||||||
@jam_track_right.finish_sign(length, md5.to_s)
|
@jam_track_right.finish_sign(length, md5.to_s)
|
||||||
|
|
|
||||||
|
|
@ -71,22 +71,22 @@ describe JamTrackRight do
|
||||||
uploader.store!(File.open(ogg_path, 'rb'))
|
uploader.store!(File.open(ogg_path, 'rb'))
|
||||||
jam_track_track.save!
|
jam_track_track.save!
|
||||||
|
|
||||||
jam_track_track[:url].should == jam_track_track.store_dir + '/' + jam_track_track.filename
|
jam_track_track[:url_48].should == jam_track_track.store_dir + '/' + jam_track_track.filename
|
||||||
|
|
||||||
# verify it's on S3
|
# verify it's on S3
|
||||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||||
s3.exists?(jam_track_track[:url]).should be_true
|
s3.exists?(jam_track_track[:url_48]).should be_true
|
||||||
s3.length(jam_track_track[:url]).should == File.size?(ogg_path)
|
s3.length(jam_track_track[:url_48]).should == File.size?(ogg_path)
|
||||||
|
|
||||||
jam_track_right = JamTrackRight.create(:user=>user, :jam_track=>jam_track)
|
jam_track_right = JamTrackRight.create(:user=>user, :jam_track=>jam_track)
|
||||||
#expect {
|
#expect {
|
||||||
JamRuby::JamTracksManager.save_jam_track_jkz(user, jam_track)
|
JamRuby::JamTracksManager.save_jam_track_jkz(user, jam_track)
|
||||||
#}.to_not raise_error(ArgumentError)
|
#}.to_not raise_error(ArgumentError)
|
||||||
jam_track_right.reload
|
jam_track_right.reload
|
||||||
jam_track_right[:url].should == jam_track_right.store_dir + '/' + jam_track_right.filename
|
jam_track_right[:url_48].should == jam_track_right.store_dir + '/' + jam_track_right.filename
|
||||||
|
|
||||||
# verify it's on S3
|
# verify it's on S3
|
||||||
url = jam_track_right[:url]
|
url = jam_track_right[:url_48]
|
||||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||||
s3.exists?(url).should be_true
|
s3.exists?(url).should be_true
|
||||||
s3.length(url).should > File.size?(ogg_path)
|
s3.length(url).should > File.size?(ogg_path)
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,12 @@ describe JamTrackTrack do
|
||||||
jam_track_track.save!
|
jam_track_track.save!
|
||||||
|
|
||||||
# verify that the uploader stores the correct path
|
# verify that the uploader stores the correct path
|
||||||
jam_track_track[:url].should == jam_track_track.store_dir + '/' + jam_track_track.filename
|
jam_track_track[:url_48].should == jam_track_track.store_dir + '/' + jam_track_track.filename
|
||||||
|
|
||||||
# verify it's on S3
|
# verify it's on S3
|
||||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||||
s3.exists?(jam_track_track[:url]).should be_true
|
s3.exists?(jam_track_track[:url_48]).should be_true
|
||||||
s3.length(jam_track_track[:url]).should == 'abc'.length
|
s3.length(jam_track_track[:url_48]).should == 'abc'.length
|
||||||
|
|
||||||
# download it via signed URL, and check contents
|
# download it via signed URL, and check contents
|
||||||
url = jam_track_track.sign_url
|
url = jam_track_track.sign_url
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,20 @@ describe JamTracksCleaner do
|
||||||
jam_track_right.signed=true
|
jam_track_right.signed=true
|
||||||
jam_track_right
|
jam_track_right
|
||||||
|
|
||||||
jam_track_right.url.store!(File.open(RIGHT_NAME))
|
jam_track_right.url_48.store!(File.open(RIGHT_NAME))
|
||||||
jam_track_right.downloaded_since_sign=true
|
jam_track_right.downloaded_since_sign=true
|
||||||
jam_track_right.save!
|
jam_track_right.save!
|
||||||
|
|
||||||
jam_track_right[:url].should == jam_track_right.store_dir + '/' + jam_track_right.filename
|
jam_track_right[:url_48].should == jam_track_right.store_dir + '/' + jam_track_right.filename
|
||||||
jam_track_right.reload
|
jam_track_right.reload
|
||||||
|
|
||||||
# Should exist after uploading:
|
# Should exist after uploading:
|
||||||
url = jam_track_right[:url]
|
url = jam_track_right[:url_48]
|
||||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||||
|
|
||||||
url.should_not be_nil
|
url.should_not be_nil
|
||||||
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
s3 = S3Manager.new(APP_CONFIG.aws_bucket, APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||||
s3.exists?(jam_track_right[:url]).should be_true
|
s3.exists?(jam_track_right[:url_48]).should be_true
|
||||||
|
|
||||||
JamRuby::JamTracksCleaner.perform
|
JamRuby::JamTracksCleaner.perform
|
||||||
s3.exists?(url).should be_true
|
s3.exists?(url).should be_true
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class ApiJamTracksController < ApiController
|
||||||
|
|
||||||
def downloads
|
def downloads
|
||||||
begin
|
begin
|
||||||
render :json => JamTrack.list_downloads(current_user, params[:limit], params[:since]), :status => 200
|
render :json => JamTrack.list_downloads(current_user, params[:limit], params[:since], params[:bitrate]), :status => 200
|
||||||
rescue
|
rescue
|
||||||
render :json => { :message => "could not produce list of files" }, :status => 403
|
render :json => { :message => "could not produce list of files" }, :status => 403
|
||||||
end
|
end
|
||||||
|
|
@ -33,11 +33,11 @@ class ApiJamTracksController < ApiController
|
||||||
|
|
||||||
def download
|
def download
|
||||||
if @jam_track_right.valid?
|
if @jam_track_right.valid?
|
||||||
if (@jam_track_right && @jam_track_right.signed && @jam_track_right.url.present? &&@jam_track_right.url.file.exists?)
|
if (@jam_track_right && @jam_track_right.signed && @jam_track_right.url_48.present? &&@jam_track_right.url_48.file.exists?)
|
||||||
@jam_track_right.update_download_count
|
@jam_track_right.update_download_count
|
||||||
@jam_track_right.last_downloaded_at = Time.now
|
@jam_track_right.last_downloaded_at = Time.now
|
||||||
@jam_track_right.save!
|
@jam_track_right.save!
|
||||||
redirect_to @jam_track_right.sign_url
|
redirect_to @jam_track_right.sign_url(120, params[:bitrate])
|
||||||
else
|
else
|
||||||
@jam_track_right.enqueue_if_needed
|
@jam_track_right.enqueue_if_needed
|
||||||
render :json => { :message => "not available, digitally signing Jam Track offline." }, :status => 202
|
render :json => { :message => "not available, digitally signing Jam Track offline." }, :status => 202
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
{"container_file": "/var/folders/fk/0ckzmddd4tq28kxbb09vckbr0000gn/T/d20150226-75079-44k4r2/jam-track-20.jkz", "coverart": null, "rsa_priv_file": "/var/folders/fk/0ckzmddd4tq28kxbb09vckbr0000gn/T/d20150226-75079-44k4r2/skey.pem", "tracks": [{"name": "/var/folders/fk/0ckzmddd4tq28kxbb09vckbr0000gn/T/d20150226-75079-44k4r2/19a1c759-94b8-4d36-92a7-00c9f3fba500.ogg", "trackName": "track_00"}], "rsa_pub_file": "/var/folders/fk/0ckzmddd4tq28kxbb09vckbr0000gn/T/d20150226-75079-44k4r2/pkey.pem", "jamktrack_info": "/var/folders/fk/0ckzmddd4tq28kxbb09vckbr0000gn/T/tmpBKhxkz"}
|
||||||
Loading…
Reference in New Issue