require 'net/http' class JupytersController < ApplicationController before_action :shixun def open #打开tpm - juypter接口 shixun = @shixun shixun_tomcat = edu_setting('cloud_bridge') uri = "#{shixun_tomcat}/bridge/jupyter/get" tpiID = "tpm#{shixun.id}" params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} logger.info "test_juypter: uri->#{uri}, params->#{params}" res = uri_post uri, params logger.info "test_juypter: #{res}" render plain: "https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/01.ipynb" end def open1 ## 打开tpi game = Game.find(2170160) shixun = game.myshixun.shixun shixun_tomcat = edu_setting('cloud_bridge') uri = "#{shixun_tomcat}/bridge/jupyter/get" tpiID = game.myshixun.id params = {tpiID: tpiID, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} res = uri_post uri, params logger.info "test_juypter: #{res}" if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") end render plain: "https://#{res['port']}.jupyter.educoder.net/notebooks/data/workspace/myshixun_#{tpiID}/01.ipynb" end def test render plain: 'test' end def save() # 保存01.ipy author_name = current_user.real_name author_email = current_user.git_mail message = "User submitted" src_url = URI("https://47519.jupyter.educoder.net/nbconvert/notebook/data/workspace/myshixun_tpm3575/01.ipynb?download=true") response = Net::HTTP.get_response(src_url) if response.code.to_i != 200 raise("获取文件内容失败:#{response.code}") end content = response.body c = GitService.update_file(repo_path: @shixun.repo_path, file_path: "01.ipynb", message: message, content: content, author_name: author_name, author_email: author_email) render plain: 'save: #{c.size}' end private def shixun @shixun = Shixun.find(3575) end end