diff --git a/app/controllers/concerns/git_common.rb b/app/controllers/concerns/git_common.rb index 452204419..1752df7cb 100644 --- a/app/controllers/concerns/git_common.rb +++ b/app/controllers/concerns/git_common.rb @@ -10,7 +10,6 @@ module GitCommon # ------------------------ # 版本库目录结构 def repository - logger.info("ssssssseeeeeeee#{params}") begin @repo_url = repo_url @repo_path @trees = GitService.file_tree(repo_path: @repo_path, path: @path) @@ -44,4 +43,16 @@ module GitCommon end end + # 为版本库添加文件 + def add_file + @path, message, content = params[:path].strip, params[:message], params[:content] + author_name, author_email = current_user.real_name, current_user.current_user.git_mail + @content = GitService.update_file(repo_path: @repo_path, + file_path: path, + message: message, + content: content, + author_name: author_name, + author_email: author_email) + end + end \ No newline at end of file diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 0064914d3..89b6dca27 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -392,59 +392,6 @@ class GamesController < ApplicationController end end - # # 文件更新;数据评测记录 - # # 生成重新评测认证码 - # # content_modified:0 表示文件没有更新;content_modified:1 表示文件有更新 - # def file_update - # path = params[:path].strip unless params[:path].blank? - # myshixun = @game.myshixun - # rev = params[:rev] ? params[:rev] : "master" - # @content_modified = 0 - # # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 - # # 自动保存的时候evaluate为0;点评测的时候为1 - # if params[:evaluate] == 1 - # record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => myshixun.shixun_id, :game_id => @game.id) - # uid_logger("-- game is #{@game.id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") - # student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - # record.update_attributes!(:student_work => student_work_time) - # end - # # 远程版本库文件内容 - # last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - # last_content = tran_base64_decode64(last_content) - # - # content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - # params[:content].gsub(/\t/, ' ') - # else - # params[:content] - # end - # if content != last_content - # @content_modified = 1 - # code_file = @g.edit_file(myshixun.gpid, current_user.login, :content => content, :file_path => path, - # :branch_name => rev, :commit_message => params[:evaluate] == 0 ? "auto commit" : "task commit") - # uid_logger("-- file update #{code_file}") - # # REDO:更新失败的处理 - # raise("文件更新失败") unless code_file - # end - # - # if record.present? - # consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - # record.update_attributes!(:file_update => consume_time) - # end - # - # # status为2说明是重新评测 - # if @game.status == 2 - # code = CODES.sample(8).join - # @resubmit = "#{code}_#{@myshixun.id}" - # end - # - # if content != last_content && code_file.blank? - # raise("实训平台繁忙(繁忙等级:81),请稍后刷新并重试") - # end - # rescue Exception => e - # uid_logger("-- file update failed #{e.message}") - # raise Educoder::TipException.new("#{e.message}") - # end - # 恢复初始代码 # 注意path为当前打开文件的path def reset_original_code diff --git a/app/views/shixuns/add_file.json.jbuilder b/app/views/shixuns/add_file.json.jbuilder new file mode 100644 index 000000000..6f22dabc8 --- /dev/null +++ b/app/views/shixuns/add_file.json.jbuilder @@ -0,0 +1,2 @@ +json.content @content +json.path @path \ No newline at end of file