diff --git a/app/controllers/bio_eddie_assets_controller.rb b/app/controllers/bio_eddie_assets_controller.rb index 836e6fa5f..bc44ba9f5 100644 --- a/app/controllers/bio_eddie_assets_controller.rb +++ b/app/controllers/bio_eddie_assets_controller.rb @@ -4,10 +4,10 @@ class BioEddieAssetsController < ApplicationController include BioEddieActions include ActiveStorage::SetCurrent - before_action :load_vars, except: :create + before_action :load_vars, except: %i(create bmt_request) before_action :load_create_vars, only: :create - before_action :check_read_permission + before_action :check_read_permission, except: %i(update create start_editing bmt_request) before_action :check_edit_permission, only: %i(update create start_editing) def create @@ -43,6 +43,23 @@ class BioEddieAssetsController < ApplicationController end end + def bmt_request + return_404 unless ENV['BIOMOLECULE_TOOLKIT_BASE_URL'] + + uri = URI.parse(ENV['BIOMOLECULE_TOOLKIT_BASE_URL']) + uri.path = request.original_fullpath.remove('/biomolecule_toolkit') + + Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| + api_request = "Net::HTTP::#{request.request_method.capitalize}".constantize.new(uri) + api_request['x-api-key'] = ENV['BIOMOLECULE_TOOLKIT_API_KEY'] if ENV['BIOMOLECULE_TOOLKIT_API_KEY'] + api_request['Content-Type'] = 'application/json' + request_body = request.body.read + api_request.body = request_body if request_body.present? + api_response = http.request(api_request) + render body: api_response.body, content_type: api_response.content_type, status: api_response.code + end + end + def start_editing create_edit_bio_eddie_activity(@asset, current_user, :start_editing) end diff --git a/config/routes.rb b/config/routes.rb index 7ee8e92ef..315caeea6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -779,6 +779,10 @@ Rails.application.routes.draw do end end + match 'biomolecule_toolkit/*path', to: 'bio_eddie_assets#bmt_request', + via: %i(get post put delete), + defaults: { format: 'json' } + post 'global_activities', to: 'global_activities#index' constraints WopiSubdomain do