From 7d889ad2a7c55a51de699524583cdb7a62b18679 Mon Sep 17 00:00:00 2001 From: guagne <8863824@gmail.com> Date: Fri, 20 Dec 2019 20:11:08 +0800 Subject: [PATCH] =?UTF-8?q?jupyter=E5=8A=A0=E5=85=A5=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/jupyters_controller.rb | 26 ++++++++++++++++++++++++++ config/routes.rb | 2 ++ 2 files changed, 28 insertions(+) diff --git a/app/controllers/jupyters_controller.rb b/app/controllers/jupyters_controller.rb index 4c03e0dd3..988cef01a 100644 --- a/app/controllers/jupyters_controller.rb +++ b/app/controllers/jupyters_controller.rb @@ -1,9 +1,35 @@ +require 'base64' class JupytersController < ApplicationController include JupyterService before_action :shixun, only: [:open, :open1, :test, :save] + + def import_with_tpm + shixun = Shixun.find_by(identifier: params[:identifier]) + + upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 + uid_logger("#########################file_params####{params["#{params[:file]}"]}") + raise "未上传文件" unless upload_file + + content = Base64.encode64(upload_file.tempfile.read) + + # upload to server + shixun_tomcat = edu_setting('cloud_bridge') + uri = "#{shixun_tomcat}/bridge/jupyter/update" + tpiID = "tpm#{shixun.id}" + params = {tpiID: tpiID, content: content} + + logger.info "test_juypter: uri->#{uri}, params->#{params}" + res = uri_post uri, params + if res && res['code'].to_i != 0 + raise("实训云平台繁忙(繁忙等级:100)") + end + + render json: {status: 0} + end + def save_with_tpi myshixun = Myshixun.find_by(identifier: params[:identifier]) jupyter_save_with_game(myshixun, params[:jupyter_port]) diff --git a/config/routes.rb b/config/routes.rb index 151cc0b32..73756ece3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,8 @@ Rails.application.routes.draw do get :reset_with_tpm get :active_with_tpm get :active_with_tpi + + post :import_with_tpm end end