You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/controllers/hack_user_lastest_codes_con...

74 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

class HackUserLastestCodesController < ApplicationController
before_action :require_login, except: [:listen_result]
before_action :find_user_hack, only: [:show, :code_debug]
def show;end
# 调试代码
def code_debug
exec_mode = "debug"
error_status = 501
error_msg = "debug_error"
oj_evaluate exec_mode, error_status, error_msg
render_ok
end
# 提交
def code_submit
exec_mode = "all"
error_status = 502
error_msg = "submit_error"
oj_evaluate exec_mode, error_status, error_msg
render_ok
end
# 接收中间件返回结果接口
def listen_result
logger.info("###########listen_result#{params}")
# debug模式
if params[:execMode] == "debug"
msg = JSON.parse(params[:msg])
if msg.present?
HackUserDebug.create(input: msg['input'], output: msg['output'], error_line: msg['output'])
end
# 只有编译出错时,才正则匹配错误行数
if params[:status] == "-4"
language = Hack.find_by_identifier(params[:tpiID]).language
regular_match_error_line params[:outPut], language
end
end
end
private
def find_user_hack
@my_hack = HackUserLastestCode.find_by(identifier: params[:identifier])
@hack = @my_hack.hack
end
def oj_evaluate exec_mode, error_status, error_msg
request_url = "#{edu_setting('cloud_bridge')}/bridge/ojs/evaluate"
testCases = Base64.urlsafe_encode64({input: params[:input]}.to_json)
debug_params = {execMode: exec_mode,
tpiID: @my_hack.identifier,
testCases: testCases,
platform: @my_hack.language,
codeFileContent: @my_hack.code,
timeLimit: @hack.time_limit, sec_key: Time.now.to_s}
interface_post request_url, debug_params, error_status, error_msg
end
# 正则错误行数
def regular_match_error_line content, language
case language
when 'Java'
when 'C'
when 'C++'
when 'Python'
end
end
end