From fc84d5454cec59cedea70548b73f2fefaa218306 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Sun, 15 May 2016 04:35:12 +0000 Subject: [PATCH 1/9] error handling for JamTrackImporter --- ruby/lib/jam_ruby/jam_track_importer.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ruby/lib/jam_ruby/jam_track_importer.rb b/ruby/lib/jam_ruby/jam_track_importer.rb index ce764a953..3032e8b12 100644 --- a/ruby/lib/jam_ruby/jam_track_importer.rb +++ b/ruby/lib/jam_ruby/jam_track_importer.rb @@ -2811,14 +2811,19 @@ module JamRuby master_track = jam_track.master_track if master_track - Dir.mktmpdir do |tmp_dir| - ogg_44100 = File.join(tmp_dir, 'input.ogg') - private_s3_manager.download(master_track.url_by_sample_rate(44), ogg_44100) + begin + Dir.mktmpdir do |tmp_dir| + ogg_44100 = File.join(tmp_dir, 'input.ogg') + private_s3_manager.download(master_track.url_by_sample_rate(44), ogg_44100) - if importer.synchronize_duration(jam_track, ogg_44100) - jam_track.save! - importer.finish("success", nil) + if importer.synchronize_duration(jam_track, ogg_44100) + jam_track.save! + importer.finish("success", nil) + end end + rescue + logger.error("ERROR: Import failed: "+$!.to_s) + importer.finish('no_duration', nil) end else importer.finish('no_duration', nil) From ce4dfa42612901b9690e9d365eae6ac76af79329 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Sat, 18 Jun 2016 13:57:39 +0000 Subject: [PATCH 2/9] VRFS-3936 recording api --- web/app/controllers/api_recordings_controller.rb | 12 ++++++++++++ web/config/routes.rb | 1 + 2 files changed, 13 insertions(+) diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index 47f5e73d3..97ee972fc 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -13,6 +13,18 @@ class ApiRecordingsController < ApiController @log || Logging.logger[ApiRecordingsController] end + def create + if request.headers['Jamk-Mobile-Env'] + result = Recording.new + result.owner = current_user + result.save + render :json => result, :status => 200 + return + end + response.status = :unprocessable_entity + render :nothing + end + def index # lists recordings created by for the current user @recordings = Recording.list_recordings(current_user, params[:created_by]) diff --git a/web/config/routes.rb b/web/config/routes.rb index ed3634dba..de2dd4ae0 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -572,6 +572,7 @@ SampleApp::Application.routes.draw do match '/recordings/uploads' => 'api_recordings#list_uploads', :via => :get, :as => 'api_recordings_list_uploads' match '/recordings/downloads' => 'api_recordings#list_downloads', :via => :get, :as => 'api_recordings_list_downloads' match '/recordings/start' => 'api_recordings#start', :via => :post, :as => 'api_recordings_start' + match '/recordings/create' => 'api_recordings#create', :via => :post, :as => 'api_recordings_create' match '/recordings/:id' => 'api_recordings#show', :via => :get, :as => 'api_recordings_detail' match '/recordings/:id/stop' => 'api_recordings#stop', :via => :post, :as => 'api_recordings_stop' match '/recordings/:id/claim' => 'api_recordings#claim', :via => :post, :as => 'api_recordings_claim' From cbfb8f35c1c8bcaf8a58cab030c61dd76916418f Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Fri, 24 Feb 2017 15:32:02 -0800 Subject: [PATCH 3/9] VRFS-3936 using Recording.create_immediately --- web/app/controllers/api_recordings_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index c6c9406a0..507369945 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -15,11 +15,11 @@ class ApiRecordingsController < ApiController def create if request.headers['Jamk-Mobile-Env'] - result = Recording.new - result.owner = current_user - result.save - render :json => result, :status => 200 - return + result = Recording.create_immediately(current_user, params) + unless result.errors.any? + render :json => result, :status => 200 + return + end end response.status = :unprocessable_entity render :nothing From 4f4757c94691a077c8aa2efa40461fac4e05dfaa Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Thu, 16 Mar 2017 11:21:53 -0700 Subject: [PATCH 4/9] VRFS-3936 index on json_stores.type column --- db/manifest | 3 ++- db/up/json_stores_type_index.sql | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 db/up/json_stores_type_index.sql diff --git a/db/manifest b/db/manifest index cf77ffe95..3e10c271f 100755 --- a/db/manifest +++ b/db/manifest @@ -372,4 +372,5 @@ retailer_interest.sql connection_role.sql retailer_payment_split.sql teacher_distribution_fields.sql -jam_track_download_rights.sql \ No newline at end of file +jam_track_download_rights.sql +json_stores_type_index.sql diff --git a/db/up/json_stores_type_index.sql b/db/up/json_stores_type_index.sql new file mode 100644 index 000000000..c6d731ff4 --- /dev/null +++ b/db/up/json_stores_type_index.sql @@ -0,0 +1 @@ +CREATE INDEX json_stores_type ON json_stores USING btree(type); From 7dcbadb75ffa643b49b778e5d04db35249b55657 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Thu, 16 Mar 2017 11:23:30 -0700 Subject: [PATCH 5/9] VRFS-3936 mobile recording json saves --- ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/models/mobile_recording.rb | 8 ++++ ruby/lib/jam_ruby/models/recording.rb | 5 +++ .../controllers/api_recordings_controller.rb | 38 +++++++++++++++++-- web/config/routes.rb | 1 + 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 ruby/lib/jam_ruby/models/mobile_recording.rb diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index cd051e8bb..1ac125372 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -317,6 +317,7 @@ require "jam_ruby/models/teacher_language" require "jam_ruby/models/teacher_genre" require "jam_ruby/models/jam_class_report" require "jam_ruby/models/campaign_spend" +require "jam_ruby/models/mobile_recording" include Jampb module JamRuby diff --git a/ruby/lib/jam_ruby/models/mobile_recording.rb b/ruby/lib/jam_ruby/models/mobile_recording.rb new file mode 100644 index 000000000..79ac04533 --- /dev/null +++ b/ruby/lib/jam_ruby/models/mobile_recording.rb @@ -0,0 +1,8 @@ +module JamRuby + class MobileRecording < JsonStore + + # this class keeps backups of mobile recording jobs + belongs_to :recording, class_name: 'JamRuby::Recording', foreign_key: :foreign_key1_id + + end +end diff --git a/ruby/lib/jam_ruby/models/recording.rb b/ruby/lib/jam_ruby/models/recording.rb index dbfd2e01e..348ab6de5 100644 --- a/ruby/lib/jam_ruby/models/recording.rb +++ b/ruby/lib/jam_ruby/models/recording.rb @@ -27,6 +27,11 @@ module JamRuby accepts_nested_attributes_for :recorded_tracks, :mixes, :claimed_recordings, allow_destroy: true + has_one :mobile_recording, + class_name: 'JamRuby::MobileRecording', + foreign_key: :foreign_key1_id, + dependent: :destroy + validate :not_already_recording, :on => :create validate :not_still_finalizing_previous, :on => :create validate :not_playback_recording, :on => :create diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index 507369945..db91059dc 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -1,7 +1,7 @@ class ApiRecordingsController < ApiController before_filter :api_signed_in_user, :except => [ :add_like ] - before_filter :lookup_recording, :only => [ :show, :stop, :claim, :discard, :keep, :delete_claim, :add_timeline, :add_video_data, :delete_video_data ] + before_filter :lookup_recording, :only => [ :show, :stop, :claim, :discard, :keep, :delete_claim, :add_timeline, :add_video_data, :delete_video_data, :mobile_update ] before_filter :lookup_recorded_track, :only => [ :download, :upload_next_part, :upload_sign, :upload_part_complete, :upload_complete ] before_filter :lookup_recorded_backing_track, :only => [ :backing_track_download, :backing_track_upload_next_part, :backing_track_upload_sign, :backing_track_upload_part_complete, :backing_track_upload_complete ] before_filter :lookup_recorded_video, :only => [ :video_upload_sign, :video_upload_start, :video_upload_complete ] @@ -13,16 +13,48 @@ class ApiRecordingsController < ApiController @log || Logging.logger[ApiRecordingsController] end + def mobile_update + mobile_rec = @recording.mobile_recording + + if mobile_rec + mobile_rec.data_blob(JSON.parse(request.body.read)) + mobile_rec.save + + unless mobile_rec.errors.any? + render :json => @recording, :status => 200 + return + end + end + response.status = :unprocessable_entity + render nothing: true + end + def create if request.headers['Jamk-Mobile-Env'] - result = Recording.create_immediately(current_user, params) + json = JSON.parse(request.body.read) + + record_params = { + name: json['title'], + description: json['description'], + genre: json['genre']['id'], + record_video: json['isVideo'], + is_public: false, # NOTE: figure out why we this one and the yt one + upload_to_youtube: false, + } + result = Recording.create_immediately(current_user, record_params) unless result.errors.any? + + mr = MobileRecording.new + mr.data_blob = json + mr.recording = result + mr.save! + render :json => result, :status => 200 return end end response.status = :unprocessable_entity - render :nothing + render nothing: true end def index diff --git a/web/config/routes.rb b/web/config/routes.rb index ac10aca9b..fa0b5b95e 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -601,6 +601,7 @@ Rails.application.routes.draw do match '/recordings/:id/video_data' => 'api_recordings#add_video_data', :via => :post, :as => 'api_recordings_video_data' match '/recordings/:id/video_data' => 'api_recordings#delete_video_data', :via => :delete, :as => 'api_recordings_video_data_delete' match '/recordings' => 'api_recordings#create_immediately', :via => :post + match '/recordings/:id/mobile_update' => 'api_recordings#mobile_update', :via => :post, :as => 'api_recordings_mobile_update' # Recordings - recorded_tracks From 368030eedc0a0e72553b50494dacc07abc4062d6 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Thu, 16 Mar 2017 17:22:54 -0700 Subject: [PATCH 6/9] VRFS-3936 mobile_recording_upload --- db/manifest | 2 +- db/up/json_stores_type_index.sql | 1 - db/up/mobile_recording_support.sql | 15 +++++ ruby/lib/jam_ruby.rb | 2 + .../uploaders/mobile_recording_uploader.rb | 25 +++++++++ ruby/lib/jam_ruby/models/mobile_recording.rb | 4 ++ .../models/mobile_recording_upload.rb | 55 +++++++++++++++++++ .../models/mobile_recording_upload_spec.rb | 42 ++++++++++++++ .../controllers/api_recordings_controller.rb | 38 ++++++++++++- web/config/routes.rb | 4 ++ 10 files changed, 185 insertions(+), 3 deletions(-) delete mode 100644 db/up/json_stores_type_index.sql create mode 100644 db/up/mobile_recording_support.sql create mode 100644 ruby/lib/jam_ruby/app/uploaders/mobile_recording_uploader.rb create mode 100644 ruby/lib/jam_ruby/models/mobile_recording_upload.rb create mode 100644 ruby/spec/jam_ruby/models/mobile_recording_upload_spec.rb diff --git a/db/manifest b/db/manifest index 3e10c271f..4d6757f21 100755 --- a/db/manifest +++ b/db/manifest @@ -373,4 +373,4 @@ connection_role.sql retailer_payment_split.sql teacher_distribution_fields.sql jam_track_download_rights.sql -json_stores_type_index.sql +mobile_recording_support.sql diff --git a/db/up/json_stores_type_index.sql b/db/up/json_stores_type_index.sql deleted file mode 100644 index c6d731ff4..000000000 --- a/db/up/json_stores_type_index.sql +++ /dev/null @@ -1 +0,0 @@ -CREATE INDEX json_stores_type ON json_stores USING btree(type); diff --git a/db/up/mobile_recording_support.sql b/db/up/mobile_recording_support.sql new file mode 100644 index 000000000..0e6c248c2 --- /dev/null +++ b/db/up/mobile_recording_support.sql @@ -0,0 +1,15 @@ +-- the type column should be indexed +CREATE INDEX json_stores_type ON json_stores USING btree(type); + +-- mobile recording media S3 upload +CREATE TABLE mobile_recording_uploads ( + id character varying(64) NOT NULL DEFAULT uuid_generate_v4(), + mobile_recording_id varchar(64) NOT NULL, + file_url varchar(1024) DEFAULT NULL, + file_name varchar(255) DEFAULT NULL, + size integer, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX mobile_recording_id_idx ON mobile_recording_uploads USING btree(mobile_recording_id); diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index 1ac125372..783d534a4 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -318,6 +318,8 @@ require "jam_ruby/models/teacher_genre" require "jam_ruby/models/jam_class_report" require "jam_ruby/models/campaign_spend" require "jam_ruby/models/mobile_recording" +require "jam_ruby/app/uploaders/mobile_recording_uploader" +require "jam_ruby/models/mobile_recording_upload" include Jampb module JamRuby diff --git a/ruby/lib/jam_ruby/app/uploaders/mobile_recording_uploader.rb b/ruby/lib/jam_ruby/app/uploaders/mobile_recording_uploader.rb new file mode 100644 index 000000000..6897a51f5 --- /dev/null +++ b/ruby/lib/jam_ruby/app/uploaders/mobile_recording_uploader.rb @@ -0,0 +1,25 @@ +# encoding: utf-8 + +class MobileRecordingUploader < CarrierWave::Uploader::Base + + def initialize(*) + super + JamRuby::UploaderConfiguration.set_aws_private_configuration(self) + end + + def store_dir + nil + end + + def md5 + @md5 ||= ::Digest::MD5.file(current_path).hexdigest + end + + def filename + model.filename if model.id + end + + def extension_white_list + %w(aac m4a mp3) + end +end diff --git a/ruby/lib/jam_ruby/models/mobile_recording.rb b/ruby/lib/jam_ruby/models/mobile_recording.rb index 79ac04533..3cb19560a 100644 --- a/ruby/lib/jam_ruby/models/mobile_recording.rb +++ b/ruby/lib/jam_ruby/models/mobile_recording.rb @@ -4,5 +4,9 @@ module JamRuby # this class keeps backups of mobile recording jobs belongs_to :recording, class_name: 'JamRuby::Recording', foreign_key: :foreign_key1_id + has_one :mobile_recording_upload, + class_name: 'JamRuby::MobileRecordingUpload', + foreign_key: :mobile_recording_id + end end diff --git a/ruby/lib/jam_ruby/models/mobile_recording_upload.rb b/ruby/lib/jam_ruby/models/mobile_recording_upload.rb new file mode 100644 index 000000000..ed25b8204 --- /dev/null +++ b/ruby/lib/jam_ruby/models/mobile_recording_upload.rb @@ -0,0 +1,55 @@ +module JamRuby + class MobileRecordingUpload < ActiveRecord::Base + include JamRuby::S3ManagerMixin + + self.table_name = 'mobile_recording_uploads' + self.primary_key = 'id' + + RECORDING_FILE_DIR = "mobile_recording_uploads" + + attr_accessible :file_url, :size, :file_name + + belongs_to :mobile_recording, + class_name: "JamRuby::MobileRecording", + foreign_key: :mobile_recording_id + + mount_uploader :file_url, MobileRecordingUploader + + before_destroy :delete_s3_files + + validates :size, :presence => true + + def self.create(mobile_recording, file, file_name) + mru = self.new + mru.file_name = file_name + mru.mobile_recording = mobile_recording + mru.size = file.size + + # save first to get a valid created_at time + mru.save! + + # now that the model exists (created_at exists), we can save the file in the correct path + mru.file_url = file + mru.save + mru + end + + def filename + self.class.construct_filename(self) + end + + def sign_url(expiration_time = 120) + s3_manager.sign_url(self[:file_url], {:expires => expiration_time, :secure => true}) + end + + private + + def self.construct_filename(mru) + "#{RECORDING_FILE_DIR}/#{mru.created_at.strftime('%Y%m%d%H%M%S')}/#{mru.mobile_recording.user_id}/#{mru.file_name}" + end + + def delete_s3_files + s3_manager({:public => true}).delete(self[:file_url]) if self[:file_url] + end + end +end diff --git a/ruby/spec/jam_ruby/models/mobile_recording_upload_spec.rb b/ruby/spec/jam_ruby/models/mobile_recording_upload_spec.rb new file mode 100644 index 000000000..400bd14b2 --- /dev/null +++ b/ruby/spec/jam_ruby/models/mobile_recording_upload_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require 'digest/md5' + +# NOTE this was cloned from music_notation_spec.rb + +describe MobileRecordingUpload do + + include UsesTempFiles + + MRU_TEMP_FILE='detail.png' + + in_directory_with_file(MRU_TEMP_FILE) + + before do + content_for_file("this is mobile recording test file") + end + + it "return empty" do + MobileRecordingUpload.all.length.should == 0 + end + + + it "should allow insertion" do + mru = MobileRecordingUpload.new + mru.file_url = File.open(MRU_TEMP_FILE) + mru.size = File.size(MRU_TEMP_FILE) + + mr = MobileRecording.new + mr.user = FactoryGirl.create(:user) + mr.save! + + mru.mobile_recording = mr + mru.save! + + File.basename(mru.file_url.path).should == mr.user_id + mru.size.should == File.size(MRU_TEMP_FILE) + + stub_const("APP_CONFIG", app_config) + mru.sign_url.should_not be_nil + + end +end diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index db91059dc..fc87630c0 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -1,7 +1,7 @@ class ApiRecordingsController < ApiController before_filter :api_signed_in_user, :except => [ :add_like ] - before_filter :lookup_recording, :only => [ :show, :stop, :claim, :discard, :keep, :delete_claim, :add_timeline, :add_video_data, :delete_video_data, :mobile_update ] + before_filter :lookup_recording, :only => [ :show, :stop, :claim, :discard, :keep, :delete_claim, :add_timeline, :add_video_data, :delete_video_data, :mobile_upload, :mobile_update, :mobile_upload_download, :mobile_upload_delete ] before_filter :lookup_recorded_track, :only => [ :download, :upload_next_part, :upload_sign, :upload_part_complete, :upload_complete ] before_filter :lookup_recorded_backing_track, :only => [ :backing_track_download, :backing_track_upload_next_part, :backing_track_upload_sign, :backing_track_upload_part_complete, :backing_track_upload_complete ] before_filter :lookup_recorded_video, :only => [ :video_upload_sign, :video_upload_start, :video_upload_complete ] @@ -13,6 +13,42 @@ class ApiRecordingsController < ApiController @log || Logging.logger[ApiRecordingsController] end + def mobile_upload + mobile_rec = @recording.mobile_recording + + if mobile_rec + mru = MobileRecordingUpload.create(mobile_rec, request.body, params[:file_name]) + + unless mobile_rec.errors.any? + render :json => @recording, :status => 200 + return + end + end + response.status = :unprocessable_entity + render nothing: true + end + + def mobile_upload_download + mobile_rec = @recording.mobile_recording + if mobile_rec && mobile_rec.mobile_recording_upload + redirect_to mobile_rec.mobile_recording_upload.sign_url + return + end + response.status = :unprocessable_entity + render nothing: true + end + + def mobile_upload_delete + mobile_rec = @recording.mobile_recording + if mobile_rec + mobile_rec.mobile_recording_upload.try(:destroy) + render :json => {}, status: 204 + return + end + response.status = :unprocessable_entity + render nothing: true + end + def mobile_update mobile_rec = @recording.mobile_recording diff --git a/web/config/routes.rb b/web/config/routes.rb index fa0b5b95e..5831ceabe 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -601,7 +601,11 @@ Rails.application.routes.draw do match '/recordings/:id/video_data' => 'api_recordings#add_video_data', :via => :post, :as => 'api_recordings_video_data' match '/recordings/:id/video_data' => 'api_recordings#delete_video_data', :via => :delete, :as => 'api_recordings_video_data_delete' match '/recordings' => 'api_recordings#create_immediately', :via => :post + match '/recordings/:id/mobile_update' => 'api_recordings#mobile_update', :via => :post, :as => 'api_recordings_mobile_update' + match '/recordings/:id/mobile_upload' => 'api_recordings#mobile_upload', :via => :post, :as => 'api_recordings_mobile_upload' + match '/recordings/:id/mobile_upload' => 'api_recordings#mobile_upload_download', :via => :get, :as => :download_mobile_recording + match '/recordings/:id/mobile_upload' => 'api_recordings#mobile_upload_delete', :via => :delete, :as => :delete_mobile_recording # Recordings - recorded_tracks From a6f9413fae517620c49b52f8ca37062427bd4dfa Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Wed, 22 Mar 2017 12:48:36 -0700 Subject: [PATCH 7/9] VRFS-3936 fixed typo in mobile_update method --- web/app/controllers/api_recordings_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/app/controllers/api_recordings_controller.rb b/web/app/controllers/api_recordings_controller.rb index fc87630c0..38447f664 100644 --- a/web/app/controllers/api_recordings_controller.rb +++ b/web/app/controllers/api_recordings_controller.rb @@ -53,7 +53,7 @@ class ApiRecordingsController < ApiController mobile_rec = @recording.mobile_recording if mobile_rec - mobile_rec.data_blob(JSON.parse(request.body.read)) + mobile_rec.data_blob = JSON.parse(request.body.read) mobile_rec.save unless mobile_rec.errors.any? @@ -74,7 +74,7 @@ class ApiRecordingsController < ApiController description: json['description'], genre: json['genre']['id'], record_video: json['isVideo'], - is_public: false, # NOTE: figure out why we this one and the yt one + is_public: false, # NOTE: figure out why we need this one and the yt one upload_to_youtube: false, } result = Recording.create_immediately(current_user, record_params) From afe8380280c11de32c59217e90354c40e65b937f Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Thu, 20 Apr 2017 01:06:25 -0700 Subject: [PATCH 8/9] VRFS-3936 had to tweak mobile recording uploads --- ruby/lib/jam_ruby/models/mobile_recording_upload.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ruby/lib/jam_ruby/models/mobile_recording_upload.rb b/ruby/lib/jam_ruby/models/mobile_recording_upload.rb index ed25b8204..259236b18 100644 --- a/ruby/lib/jam_ruby/models/mobile_recording_upload.rb +++ b/ruby/lib/jam_ruby/models/mobile_recording_upload.rb @@ -28,8 +28,12 @@ module JamRuby # save first to get a valid created_at time mru.save! + # CarrierWave says we need a file extension, doesn't get provided + tmpfile = Tempfile.new([file_name, File.extname(file_name)]) + tmpfile.write(file) + # now that the model exists (created_at exists), we can save the file in the correct path - mru.file_url = file + mru.file_url = tmpfile mru.save mru end From af4678cbed58a53735d6f9f7fbfbe8db1eba1417 Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 24 Apr 2017 11:21:11 -0700 Subject: [PATCH 9/9] VRFS-3936 mobile purchase sync fixes --- web/app/controllers/api_jam_tracks_controller.rb | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/web/app/controllers/api_jam_tracks_controller.rb b/web/app/controllers/api_jam_tracks_controller.rb index 13a6723a6..ff7cbf6f2 100644 --- a/web/app/controllers/api_jam_tracks_controller.rb +++ b/web/app/controllers/api_jam_tracks_controller.rb @@ -102,7 +102,6 @@ class ApiJamTracksController < ApiController if params[:mixcheck] checksum = JamTrackMixdown.mixdownChecksum(current_user.id, jtid) head :ok, checksum: checksum - return else # 204: nothing purchased for user # 200: jamtrack purchase for user confirmed @@ -111,21 +110,12 @@ class ApiJamTracksController < ApiController .limit(1) .blank? 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 + elsif params[:syncbuys].present? + head :ok, purchasecount: JamTrackRight.where(user_id: current_user.id).count end - head(:ok) + head(:ok) unless performed? end def purchased