From d82a676d933d99649aa7e883baf6bc8e17d49d27 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 19 Jan 2023 11:53:34 +0800 Subject: [PATCH] feat(problem/remote): re-crawl remote problem --- web/app/controllers/problem_data_manage.php | 1 + .../controllers/problem_managers_manage.php | 12 ++- .../controllers/problem_statement_manage.php | 94 ++++++++++++++++++- 3 files changed, 97 insertions(+), 10 deletions(-) diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php index 75bd106..7300f88 100644 --- a/web/app/controllers/problem_data_manage.php +++ b/web/app/controllers/problem_data_manage.php @@ -10,6 +10,7 @@ requirePHPLib('data'); UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404(); UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403(); +UOJProblem::cur()->type() === 'local' || UOJResponse::page404(); $problem = UOJProblem::info(); $problem_extra_config = UOJProblem::cur()->getExtraConfig(); diff --git a/web/app/controllers/problem_managers_manage.php b/web/app/controllers/problem_managers_manage.php index a93b4a6..b381daa 100644 --- a/web/app/controllers/problem_managers_manage.php +++ b/web/app/controllers/problem_managers_manage.php @@ -82,11 +82,13 @@ if (isSuperUser(Auth::user())) { 管理者 - + type() == 'local') : ?> + +
diff --git a/web/app/controllers/problem_statement_manage.php b/web/app/controllers/problem_statement_manage.php index 3aa2e63..1cea27a 100644 --- a/web/app/controllers/problem_statement_manage.php +++ b/web/app/controllers/problem_statement_manage.php @@ -80,6 +80,77 @@ $difficulty_form->handle = function () { ]); }; $difficulty_form->runAtServer(); + +if (UOJProblem::cur()->type() == 'remote') { + $remote_online_judge = UOJProblem::cur()->getExtraConfig('remote_online_judge'); + $remote_problem_id = UOJProblem::cur()->getExtraConfig('remote_problem_id'); + $remote_provider = UOJRemoteProblem::$providers[$remote_online_judge]; + + $re_crawl_form = new UOJForm('re_crawl'); + $re_crawl_form->appendHTML(<< +
  • 远程题库:{$remote_provider['name']}
  • +
  • 远程题号:{$remote_problem_id}
  • + + EOD); + $re_crawl_form->config['submit_button']['text'] = '重新爬取'; + $re_crawl_form->handle = function () use ($remote_online_judge, $remote_problem_id, $remote_provider) { + try { + $data = UOJRemoteProblem::getProblemBasicInfo($remote_online_judge, $remote_problem_id); + } catch (Exception $e) { + $data = null; + UOJLog::error($e->getMessage()); + } + + if ($data === null) { + UOJResponse::page500('题目抓取失败,可能是题目不存在或者没有题面!如果题目没有问题,请稍后再试。返回'); + } + + $submission_requirement = [ + [ + "name" => "answer", + "type" => "source code", + "file_name" => "answer.code", + "languages" => $remote_provider['languages'], + ] + ]; + $enc_submission_requirement = json_encode($submission_requirement); + + $extra_config = [ + 'remote_online_judge' => $remote_online_judge, + 'remote_problem_id' => $remote_problem_id, + 'time_limit' => $data['time_limit'], + 'memory_limit' => $data['memory_limit'], + ]; + $enc_extra_config = json_encode($extra_config); + + DB::update([ + "update problems", + "set", [ + "title" => $data['title'], + "submission_requirement" => $enc_submission_requirement, + "extra_config" => $enc_extra_config, + "difficulty" => $data['difficulty'] ?: -1, + ], + "where", [ + "id" => UOJProblem::info('id'), + ], + ]); + + DB::update([ + "update problems_contents", + "set", [ + "remote_content" => HTML::purifier()->purify($data['statement']), + ], + "where", [ + "id" => UOJProblem::info('id'), + ], + ]); + + redirectTo(UOJProblem::cur()->getUri()); + }; + $re_crawl_form->runAtServer(); +} ?> @@ -102,11 +173,13 @@ $difficulty_form->runAtServer(); 管理者 - + type() == 'local') : ?> + +
    @@ -261,6 +334,17 @@ $difficulty_form->runAtServer(); printHTML() ?>
    + + type() == 'remote') : ?> +
    +
    + 重新爬取题目信息 +
    +
    + printHTML() ?> +
    +
    +