diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 0d8604aac..efc073c86 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -41,7 +41,8 @@ module GitHelper # 更新文件代码 # content: 文件内容;message:提交描述 def update_file_content(content, repo_path, path, mail, username, message) - GitService.update_file(repo_path: repo_path, file_path: path, message: message, + content = Base64.encode64(content) + GitService.update_file_base64(repo_path: repo_path, file_path: path, message: message, content: content, author_name: username, author_email: mail) end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 938d42c2f..055c656eb 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -962,8 +962,11 @@ class GamesController < ApplicationController shixun = game.myshixun.shixun shixun_tomcat = edu_setting('cloud_bridge') service_host = edu_setting('vnc_url') + tpiGitURL = "#{edu_setting('git_address_domain')}/#{game.myshixun.repo_path}" + uri = "#{shixun_tomcat}/bridge/vnc/getvnc" - params = {tpiID: game.myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}"} + params = {tpiID: game.myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}", + tpiGitURL: tpiGitURL} res = uri_post uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") diff --git a/app/controllers/jupyters_controller.rb b/app/controllers/jupyters_controller.rb index ecb411b36..81df43759 100644 --- a/app/controllers/jupyters_controller.rb +++ b/app/controllers/jupyters_controller.rb @@ -76,7 +76,7 @@ class JupytersController < ApplicationController def active_with_tpi myshixun = Myshixun.find_by(identifier: params[:identifier]) - jupyter_active_tpm(myshixun) + jupyter_active_tpi(myshixun) render json: {status: 0} end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 67bec877b..7847d58ed 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -216,10 +216,11 @@ class MyshixunsController < ApplicationController old_time = Time.now.to_i begin shixun_tomcat = edu_setting('tomcat_webssh') + tpiGitURL = "#{edu_setting('git_address_domain')}/#{@myshixun.repo_path}" uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo" # 由于中间层采用混合云的方式,因为local参数表示在有文件生成的实训是在本地生成,还是在其他云端生成评测文件 local = @myshixun.shixun.challenges.where.not(show_type: -1).count == 0 - params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), local: local, + params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), local: local, tpiGitURL: tpiGitURL, containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))} res = uri_post uri, params if res && res['code'].to_i != 0 diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 7867d063e..eedac2595 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -2,16 +2,30 @@ # # 文档在 https://www.showdoc.cc/127895880302646?page_id=1077512172693249 # +require 'faraday' + class GitService class << self - ['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits', 'add_tree', 'delete_file'].each do |method| + ['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', 'file_content', 'commits', + 'add_tree', 'delete_file', 'update_file_base64'].each do |method| define_method method do |params| post(method, params) end end + def make_new_multipar_file(full_file_path) + Faraday::FilePart.new(full_file_path, 'application/octet-stream') + end + + #上传二进制文件 + #参数构造形式 + # {a: 'a', file: make_new_multipar_file('1.txt') } + def update_file_binary(params) + post_form('update_file', params) + end + private def root_url @@ -24,6 +38,19 @@ class GitService Rails.logger end + def post_form(action,params) + conn = Faraday.new(root_url) do |f| + f.request :multipart + f.request :url_encoded + f.adapter :net_http + end + + resp = conn.post("/api/#{action}", params) + + body = resp.body + parse_return(body) + end + def post(action, params) uri = URI.parse("#{root_url}/api/#{action}") https = Net::HTTP.new(uri.host, uri.port) @@ -32,6 +59,11 @@ class GitService req.body = params.to_json res = https.request(req) body = res.body + + parse_return(body) + end + + def parse_return(body) logger.info("--uri_exec: .....res is #{body}") content = JSON.parse(body) diff --git a/app/templates/shixun_work/shixun_work.html.erb b/app/templates/shixun_work/shixun_work.html.erb index bbc81f373..76a269f3f 100644 --- a/app/templates/shixun_work/shixun_work.html.erb +++ b/app/templates/shixun_work/shixun_work.html.erb @@ -101,85 +101,86 @@ -
- 图形统计 -
-+ 图形统计 +
+- 实训详情 -
- <%#= ApplicationController.helpers.javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/javascript-hint", "/codemirror/addon/selection/active-line", "/codemirror/addon/lint/javascript-lint", "/codemirror/addon/lint/css-lint", "/codemirror/addon/lint/lint", "/codemirror/addon/lint/json-lint", "/editormd/lib/codemirror/addon/lint/css-lint" %> - <% @games.each_with_index do |game, index| %> -+
+ 实训详情 +
+ <%#= ApplicationController.helpers.javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/javascript-hint", "/codemirror/addon/selection/active-line", "/codemirror/addon/lint/javascript-lint", "/codemirror/addon/lint/css-lint", "/codemirror/addon/lint/lint", "/codemirror/addon/lint/json-lint", "/editormd/lib/codemirror/addon/lint/css-lint" %> + <% @games.each_with_index do |game, index| %> +第<%= index+1 %>关<%= game.challenge.subject %> -
- -评测次数 | -评测信息 | - - - <% outputs = game.outputs.group("query_index") %> - <% max_query = outputs.map(&:query_index).max %> - <% outputs.reverse.try(:each) do |output| %> -
---|---|
<%= max_query == output.query_index ? "最后一次" : "第#{output.query_index}次" %> | -<%= output_detail(game, output) %> | -
- 最近通过的代码 -
-评测次数 | +评测信息 | + + + <% outputs = game.outputs.group("query_index") %> + <% max_query = outputs.map(&:query_index).max %> + <% outputs.reverse.try(:each) do |output| %> +
---|---|
<%= max_query == output.query_index ? "最后一次" : "第#{output.query_index}次" %> | +<%= output_detail(game, output) %> | +
+ 最近通过的代码 +
+