feat(problem/remote): re-crawl remote problem

This commit is contained in:
Baoshuo Ren 2023-01-19 11:53:34 +08:00
parent 73f5298911
commit d82a676d93
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 97 additions and 10 deletions

View File

@ -10,6 +10,7 @@ requirePHPLib('data');
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404(); UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403(); UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403();
UOJProblem::cur()->type() === 'local' || UOJResponse::page404();
$problem = UOJProblem::info(); $problem = UOJProblem::info();
$problem_extra_config = UOJProblem::cur()->getExtraConfig(); $problem_extra_config = UOJProblem::cur()->getExtraConfig();

View File

@ -82,11 +82,13 @@ if (isSuperUser(Auth::user())) {
管理者 管理者
</a> </a>
</li> </li>
<?php if (UOJProblem::cur()->type() == 'local') : ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab"> <a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab">
数据 数据
</a> </a>
</li> </li>
<?php endif ?>
</ul> </ul>
<div class="card card-default"> <div class="card card-default">

View File

@ -80,6 +80,77 @@ $difficulty_form->handle = function () {
]); ]);
}; };
$difficulty_form->runAtServer(); $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(<<<EOD
<ul>
<li>远程题库:{$remote_provider['name']}</li>
<li>远程题号:{$remote_problem_id}</li>
</ul>
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('题目抓取失败,可能是题目不存在或者没有题面!如果题目没有问题,请稍后再试。<a href="">返回</a>');
}
$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();
}
?> ?>
<?php echoUOJPageHeader('题面编辑 - ' . HTML::stripTags(UOJProblem::info('title'))) ?> <?php echoUOJPageHeader('题面编辑 - ' . HTML::stripTags(UOJProblem::info('title'))) ?>
@ -102,11 +173,13 @@ $difficulty_form->runAtServer();
管理者 管理者
</a> </a>
</li> </li>
<?php if (UOJProblem::cur()->type() == 'local') : ?>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab"> <a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab">
数据 数据
</a> </a>
</li> </li>
<?php endif ?>
</ul> </ul>
<div class="card card-default"> <div class="card card-default">
@ -261,6 +334,17 @@ $difficulty_form->runAtServer();
<?php $difficulty_form->printHTML() ?> <?php $difficulty_form->printHTML() ?>
</div> </div>
</div> </div>
<?php if (UOJProblem::cur()->type() == 'remote') : ?>
<div class="card mt-3">
<div class="card-header fw-bold">
重新爬取题目信息
</div>
<div class="card-body">
<?php $re_crawl_form->printHTML() ?>
</div>
</div>
<?php endif ?>
</aside> </aside>
</div> </div>