diff --git a/Gemfile b/Gemfile index f2e3b45e..e9ce24fd 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,8 @@ gem 'tzinfo', '~> 1.2' gem 'open_id_authentication' gem 'protected_attributes_continued', '~> 1.8.2' gem 'ruby-openid' +gem 'fog-google' +gem 'fog-local' gem 'rack-offline', '>= 0.6.4' diff --git a/Gemfile.lock b/Gemfile.lock index 11ded4f3..5a25ae1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,16 +62,100 @@ GEM climate_control (0.2.0) concurrent-ruby (1.1.9) crass (1.0.6) + declarative (0.0.20) docile (1.4.0) erubi (1.10.0) + excon (0.90.0) execjs (2.7.0) faker (2.19.0) i18n (>= 1.6, < 2) + faraday (1.9.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.3) + multipart-post (>= 1.2, < 3) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) ffi (1.15.5) + fog-core (2.1.0) + builder + excon (~> 0.58) + formatador (~> 0.2) + mime-types + fog-google (1.17.0) + fog-core (<= 2.1.0) + fog-json (~> 1.2) + fog-xml (~> 0.1.0) + google-apis-compute_v1 (~> 0.14) + google-apis-dns_v1 (~> 0.12) + google-apis-iamcredentials_v1 (~> 0.6) + google-apis-monitoring_v3 (~> 0.12) + google-apis-pubsub_v1 (~> 0.7) + google-apis-sqladmin_v1beta4 (~> 0.13) + google-apis-storage_v1 (~> 0.6) + google-cloud-env (~> 1.2) + fog-json (1.2.0) + fog-core + multi_json (~> 1.10) + fog-local (0.8.0) + fog-core (>= 1.27, < 3.0) + fog-xml (0.1.4) + fog-core + nokogiri (>= 1.5.11, < 2.0.0) font-awesome-rails (4.7.0.8) railties (>= 3.2, < 8.0) + formatador (0.3.0) globalid (0.4.2) activesupport (>= 4.2.0) + google-apis-compute_v1 (0.23.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-core (0.4.2) + addressable (~> 2.5, >= 2.5.1) + googleauth (>= 0.16.2, < 2.a) + httpclient (>= 2.8.1, < 3.a) + mini_mime (~> 1.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.a) + rexml + webrick + google-apis-dns_v1 (0.18.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-iamcredentials_v1 (0.10.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-monitoring_v3 (0.20.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-pubsub_v1 (0.12.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-sqladmin_v1beta4 (0.22.0) + google-apis-core (>= 0.4, < 2.a) + google-apis-storage_v1 (0.11.0) + google-apis-core (>= 0.4, < 2.a) + google-cloud-env (1.5.0) + faraday (>= 0.17.3, < 2.0) + googleauth (1.1.0) + faraday (>= 0.17.3, < 2.0) + jwt (>= 1.4, < 3.0) + memoist (~> 0.16) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (>= 0.16, < 2.a) + httpclient (2.8.3) i18n (1.8.11) concurrent-ruby (~> 1.0) jquery-rails (4.4.0) @@ -79,6 +163,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.5.1) + jwt (2.3.0) libv8 (3.16.14.19) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) @@ -91,6 +176,7 @@ GEM marcel (0.3.3) mimemagic (~> 0.3.2) matrix (0.4.2) + memoist (0.16.2) method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) @@ -102,6 +188,8 @@ GEM mini_portile2 (2.6.1) minitest (5.15.0) msgpack (1.4.2) + multi_json (1.15.0) + multipart-post (2.1.1) mysql2 (0.5.3) nio4r (2.5.8) nokogiri (1.12.5) @@ -109,6 +197,7 @@ GEM racc (~> 1.4) open_id_authentication (1.3.0) rack-openid (~> 1.3) + os (1.1.4) paperclip (6.1.0) activemodel (>= 4.2.0) activesupport (>= 4.2.0) @@ -176,9 +265,14 @@ GEM redcarpet (3.5.1) ref (2.0.0) regexp_parser (2.2.0) + representable (3.1.1) + declarative (< 0.1.0) + trailblazer-option (>= 0.1.1, < 0.2.0) + uber (< 0.2.0) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) + retriable (3.1.2) rexml (3.2.5) rmagick (4.2.4) rubocop (1.25.0) @@ -197,10 +291,16 @@ GEM rubocop-ast (>= 0.4.0) ruby-openid (2.9.2) ruby-progressbar (1.11.0) + ruby2_keywords (0.0.5) rubyzip (2.3.2) selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) + signet (0.16.0) + addressable (~> 2.8) + faraday (>= 0.17.3, < 2.0) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -223,11 +323,14 @@ GEM ref thor (1.1.0) thread_safe (0.3.6) + trailblazer-option (0.1.2) tzinfo (1.2.9) thread_safe (~> 0.1) + uber (0.1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (2.1.0) + webrick (1.7.0) websocket-driver (0.7.3) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -244,6 +347,8 @@ DEPENDENCIES bootsnap (~> 1.10.1) capybara faker (~> 2.19.0) + fog-google + fog-local font-awesome-rails jquery-rails listen (~> 3.7.1) diff --git a/Makefile b/Makefile index 3e74f690..18f0fbf1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ endef redeploy-container: docker-compose build - docker-compose down --volumes + docker-compose down docker-compose up -d $(call wait_for_container) docker-compose logs diff --git a/app/assets/javascripts/analyze.js b/app/assets/javascripts/analyze.js index 97051e47..0604cdb3 100644 --- a/app/assets/javascripts/analyze.js +++ b/app/assets/javascripts/analyze.js @@ -290,13 +290,6 @@ $W = { f.submit(); }, - set_sample_row: function() { - var rownum = prompt('Enter the percentage from the top edge from which you would like to extract a spectrum.','100') - $("#imagelink")[0].onclick = "" - $('#imagelink').tooltip('destroy') - if (rownum) window.location = '/spectrums/setsamplerow/'+$W.spectrum_id+'?row='+rownum/100.00 - }, - click_to_set_sample_row: function() { $("#imagelink")[0].onclick = "" $('#imagelink').tooltip('destroy') diff --git a/app/controllers/spectrums_controller.rb b/app/controllers/spectrums_controller.rb index a6d077dd..c51aeaae 100755 --- a/app/controllers/spectrums_controller.rb +++ b/app/controllers/spectrums_controller.rb @@ -468,21 +468,6 @@ def match render html: @spectrum.find_match_in_set(params[:set]).to_json end - # Start doing this client side! - def setsamplerow - require 'rubygems' - require 'rmagick' - @spectrum = Spectrum.find params[:id] - require_ownership(@spectrum) - image = Magick::ImageList.new('public' + (@spectrum.photo.url.split('?')[0]).gsub('%20', ' ')) - @spectrum.sample_row = (params[:row].to_f * image.rows) - @spectrum.extract_data - @spectrum.save - flash[:warning] = "If this spectrum image is not perfectly vertical, you may need to recalibrate after setting a new cross-section." - redirect_to spectrum_path(@spectrum) - end - - # Start doing this client side! def find_brightest_row @spectrum = Spectrum.find params[:id] require_ownership(@spectrum) diff --git a/app/models/spectrum.rb b/app/models/spectrum.rb index 6efb3a15..0f20b42f 100755 --- a/app/models/spectrum.rb +++ b/app/models/spectrum.rb @@ -114,7 +114,8 @@ def self.weekly_tallies # finds the brightest row of the image and uses that as its sample row def find_brightest_row - image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' ')) + photo.copy_to_local_file(:original,local_photo_path) + image = Magick::ImageList.new(local_photo_path) brightest_row = 0 brightest = 0 # sum brightness for each row @@ -140,7 +141,8 @@ def find_brightest_row def extract_data pixels = [] - image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' ')) + photo.copy_to_local_file(:original,local_photo_path) + image = Magick::ImageList.new(local_photo_path) # saved sample_row may be greater than image height, so temporarily compensate, # but preserve sample_row in case we rotate back or something self.sample_row = image.rows - 2 if sample_row > image.rows @@ -278,17 +280,19 @@ def clone_calibration(clone_id) # rotate clockwise def rotate - image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' ')) + photo.copy_to_local_file(:original,local_photo_path) + image = Magick::ImageList.new(local_photo_path) image.rotate!(-90) - image.write('public' + photo.url) + image.write(local_photo_path) photo.reprocess! end # horizontally flips image to match reversed spectrum, toggles 'reversed' flag def reverse - image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' ')) + photo.copy_to_local_file(:original,local_photo_path) + image = Magick::ImageList.new(local_photo_path) image.flop! - image.write('public' + photo.url) + image.write(local_photo_path) self.reversed = !reversed photo.reprocess! end @@ -629,4 +633,10 @@ def find_similar(range) def spectrum_params params.require(:spectrum).permit(:title, :author, :user_id, :notes, :photo, :video_row, :data) end + + def local_photo_path + #'public' + (photo.url.split('?')[0]).gsub('%20', ' ') + "/tmp/#{self.id}" + end + end diff --git a/config/initializers/paperclip_string.rb b/config/initializers/paperclip_string.rb index 69a620d0..cbe60a07 100644 --- a/config/initializers/paperclip_string.rb +++ b/config/initializers/paperclip_string.rb @@ -4,6 +4,17 @@ # Paperclip.options[:command_path] = "/usr/bin/identify" # Paperclip.options[:command_path] = "/usr/local/bin" +Paperclip::Attachment.default_options[:storage] = :fog +Paperclip::Attachment.default_options[:fog_directory] = ENV["GOOGLE_STORAGE_BUCKET_NAME"] || '' +Paperclip::Attachment.default_options[:path] = ":rails_root/public/system/:attachment/:id/:style/:filename" +Paperclip::Attachment.default_options[:fog_credentials] = { + provider: ENV["FOG_PROVIDER"] || "Local", + local_root: "#{Rails.root}/public", + google_project: 'public-lab' , + google_json_key_location: ENV["GOOGLE_JSON_KEY_FILE"] || '' +} +Paperclip::Attachment.default_options[:fog_host] = "" + # Thank you to http://bendangelo.me/?p=60 module Paperclip # converts a string into a file for paperclip to save diff --git a/config/routes.rb b/config/routes.rb index b3d9f2ed..f35294c4 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -160,7 +160,6 @@ get 'spectrums/rss' => 'spectrums#rss' get 'spectrums/find_brightest_row' => 'spectrums#find_brightest_row' get 'spectrums/upload' => 'spectrums#upload' - get 'spectrums/setsamplerow' => 'spectrums#setsamplerow' get 'spectrums/rotate' => 'spectrums#rotate' get 'spectrums/fork' => 'spectrums#fork' get 'spectrums/reverse' => 'spectrums#reverse' diff --git a/docker-compose.yml b/docker-compose.yml index 081e27b7..a4478340 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,11 @@ services: environment: - PORT=${PORT} - POOL_SIZE=${POOL_SIZE} + - GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET} + - GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY} + - GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME} + - GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE} + - FOG_PROVIDER=${FOG_PROVIDER} ports: - 127.0.0.1:${PORT:-5000}:${PORT:-5000} depends_on: diff --git a/test/controllers/spectrums_controller_test.rb b/test/controllers/spectrums_controller_test.rb index 9911dc7d..cc0f9664 100755 --- a/test/controllers/spectrums_controller_test.rb +++ b/test/controllers/spectrums_controller_test.rb @@ -405,17 +405,6 @@ class SpectrumsControllerTest < ActionController::TestCase assert_response :redirect end - test 'should set sample row to spectrum' do - session[:user_id] = users(:admin).id - spectrum = Spectrum.last - spectrum.image_from_dataurl('data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7') - spectrum.save - post :setsamplerow, params: { id: spectrum.id } - assert_equal "If this spectrum image is not perfectly vertical, you may need to recalibrate after setting a new cross-section.", flash[:warning] - assert_response :redirect - assert_redirected_to spectrum_path(spectrum) - end - test 'should do clone search' do get :clone_search, params: { id: Spectrum.first.id,