feat: testcase download
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-09-20 13:10:25 +08:00
parent e0cffaa762
commit 67c29e3add
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
6 changed files with 133 additions and 9 deletions

View File

@ -5,12 +5,12 @@
become403Page(UOJLocale::get('need login')); become403Page(UOJLocale::get('need login'));
} }
if (!isNormalUser($myUser)) { if (!isNormalUser($myUser) && $_GET['type'] != 'attachment') {
become403Page(); become403Page();
} }
switch ($_GET['type']) { switch ($_GET['type']) {
case 'problem': case 'attachment':
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page(); become404Page();
} }
@ -33,12 +33,96 @@
$id = $_GET['id']; $id = $_GET['id'];
$file_name = "/var/uoj_data/$id/download.zip"; $file_name = "/var/uoj_data/$id/download.zip";
$download_name = "problem_$id.zip"; $download_name = "problem_{$id}_attachment.zip";
break; break;
case 'problem':
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
}
if (!isProblemVisibleToUser($problem, $myUser)) {
become404Page();
}
$id = $_GET['id'];
$file_name = "/var/uoj_data/$id.zip";
$download_name = "problem_$id.zip";
break;
case 'testcase':
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
become404Page();
}
if (!isProblemVisibleToUser($problem, $myUser)) {
become404Page();
}
$id = $_GET['id'];
$problem_conf = getUOJConf("/var/uoj_data/$id/problem.conf");
if ($problem_conf == -1 || $problem_conf == -2) {
become404Page();
}
if (!validateUInt($_GET['testcase_id'])) {
become404Page();
}
$testcase_id = $_GET['testcase_id'];
$testcase_group = isset($_GET['testcase_group']) && $_GET['testcase_group'] == 'extra' ? 'extra' : 'normal';
if ($testcase_group == 'extra') {
$n_ex_tests = getUOJConfVal($problem_conf, 'n_ex_tests', 0);
if ($testcase_id < 1 || $testcase_id > $n_ex_tests) {
become404Page();
}
switch ($_GET['testcase_type']) {
case 'input':
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
$download_name = getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
break;
case 'output':
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
$download_name = getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
break;
default:
become404Page();
}
} else {
$n_tests = getUOJConfVal($problem_conf, 'n_tests', 10);
if ($testcase_id < 1 || $testcase_id > $n_tests) {
become404Page();
}
switch ($_GET['testcase_type']) {
case 'input':
$file_name = "/var/uoj_data/$id/" . getUOJProblemInputFileName($problem_conf, $testcase_id);
$download_name = getUOJProblemInputFileName($problem_conf, $testcase_id);
break;
case 'output':
$file_name = "/var/uoj_data/$id/" . getUOJProblemOutputFileName($problem_conf, $testcase_id);
$download_name = getUOJProblemOutputFileName($problem_conf, $testcase_id);
break;
default:
become404Page();
}
}
break;
case 'testlib.h': case 'testlib.h':
$file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h"; $file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h";
$download_name = "testlib.h"; $download_name = "testlib.h";
break; break;
default: default:
become404Page(); become404Page();
} }

View File

@ -242,7 +242,10 @@ EOD
<h1 class="col-md-7 text-center"><?= $problem_letter ?>. <?= $problem['title'] ?></h1> <h1 class="col-md-7 text-center"><?= $problem_letter ?>. <?= $problem['title'] ?></h1>
<div class="col-md-2 text-right" id="contest-countdown"></div> <div class="col-md-2 text-right" id="contest-countdown"></div>
</div> </div>
<a role="button" class="btn btn-info float-right" href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a> <div class="btn-group float-right" role="group">
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=attachment&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-download-alt"></span> 附件下载</a>
<a role="button" class="btn btn-info" href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
</div>
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?> <?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
<script type="text/javascript"> <script type="text/javascript">
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>'); checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
@ -251,7 +254,11 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
<?php endif ?> <?php endif ?>
<?php else: ?> <?php else: ?>
<h1 class="page-header text-center">#<?= $problem['id']?>. <?= $problem['title'] ?></h1> <h1 class="page-header text-center">#<?= $problem['id']?>. <?= $problem['title'] ?></h1>
<a role="button" class="btn btn-info float-right" href="/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a> <div class="btn-group float-right" role="group">
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=problem&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-tasks"></span> 测试数据</a>
<a role="button" class="btn btn-primary" href="<?= HTML::url("/download.php?type=attachment&id={$problem['id']}") ?>"><span class="glyphicon glyphicon-download-alt"></span> 附件下载</a>
<a role="button" class="btn btn-info" href="/problem/<?= $problem['id'] ?>/statistics"><span class="glyphicon glyphicon-stats"></span> <?= UOJLocale::get('problems::statistics') ?></a>
</div>
<?php endif ?> <?php endif ?>
<ul class="nav nav-tabs" role="tablist"> <ul class="nav nav-tabs" role="tablist">

View File

@ -125,7 +125,6 @@
$info_form = new UOJForm('info'); $info_form = new UOJForm('info');
$http_host = HTML::escape(UOJContext::httpHost()); $http_host = HTML::escape(UOJContext::httpHost());
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
$info_form->appendHTML(<<<EOD $info_form->appendHTML(<<<EOD
<div class="form-group row"> <div class="form-group row">
<!--<label class="col-sm-3 control-label">zip上传数据</label> <!--<label class="col-sm-3 control-label">zip上传数据</label>
@ -140,6 +139,19 @@
</div> </div>
EOD EOD
); );
$attachment_url = HTML::url("/download.php?type=attachment&id={$problem['id']}");
$info_form->appendHTML(<<<EOD
<div class="form-group row">
<label class="col-sm-3 control-label">problem_{$problem['id']}_attachment.zip</label>
<div class="col-sm-9">
<div class="form-control-static">
<a href="$attachment_url">$attachment_url</a>
</div>
</div>
</div>
EOD
);
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
$info_form->appendHTML(<<<EOD $info_form->appendHTML(<<<EOD
<div class="form-group row"> <div class="form-group row">
<label class="col-sm-3 control-label">problem_{$problem['id']}.zip</label> <label class="col-sm-3 control-label">problem_{$problem['id']}.zip</label>

View File

@ -136,6 +136,9 @@
<?php <?php
$REQUIRE_LIB['shjs'] = ""; $REQUIRE_LIB['shjs'] = "";
?> ?>
<script>
var problem_id = parseInt('<?= $submission['problem_id'] ?>');
</script>
<?php echoUOJPageHeader(UOJLocale::get('problems::submission').' #'.$submission['id']) ?> <?php echoUOJPageHeader(UOJLocale::get('problems::submission').' #'.$submission['id']) ?>
<?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?> <?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?>

View File

@ -616,7 +616,7 @@ class JudgementDetailsPrinter {
if ($this->styler->collapse_in) { if ($this->styler->collapse_in) {
$accordion_collapse_class .= ' in'; $accordion_collapse_class .= ' in';
} }
echo '<div id="', $accordion_collapse, '" class="', $accordion_collapse_class, '">'; echo '<div id="', $accordion_collapse, '" class="uoj-testcase ', $accordion_collapse_class, '" data-test=' . $test_num . '>';
echo '<div class="card-body">'; echo '<div class="card-body">';
$this->_print_c($node); $this->_print_c($node);
@ -680,11 +680,11 @@ class JudgementDetailsPrinter {
echo '</div>'; echo '</div>';
} }
} elseif ($node->nodeName == 'in') { } elseif ($node->nodeName == 'in') {
echo "<h4>input:</h4><pre>\n"; echo "<h4>input: <a class=\"uoj-testcase-download-input\"></a></h4><pre>\n";
$this->_print_c($node); $this->_print_c($node);
echo "\n</pre>"; echo "\n</pre>";
} elseif ($node->nodeName == 'out') { } elseif ($node->nodeName == 'out') {
echo "<h4>output:</h4><pre>\n"; echo "<h4>output: <a class=\"uoj-testcase-download-output\"></a></h4><pre>\n";
$this->_print_c($node); $this->_print_c($node);
echo "\n</pre>"; echo "\n</pre>";
} elseif ($node->nodeName == 'res') { } elseif ($node->nodeName == 'res') {

View File

@ -354,6 +354,23 @@ $.fn.countdown = function(rest, callback) {
}); });
}; };
$.fn.uoj_testcase = function() {
return this.each(function() {
var id = parseInt($(this).data('test'));
if (id > 0 && problem_id) {
$('.uoj-testcase-download-input', this)
.html('<span class="glyphicon glyphicon-download-alt"></span> 下载')
.attr('href', '/download.php?type=testcase&id=' + problem_id + '&testcase_id=' + id + '&testcase_type=input')
.addClass('btn btn-secondary btn-sm float-right');
$('.uoj-testcase-download-output', this)
.html('<span class="glyphicon glyphicon-download-alt"></span> 下载')
.attr('href', '/download.php?type=testcase&id=' + problem_id + '&testcase_id=' + id + '&testcase_type=output')
.addClass('btn btn-secondary btn-sm float-right');
}
});
}
// update_judgement_status // update_judgement_status
update_judgement_status_list = [] update_judgement_status_list = []
function update_judgement_status_details(id) { function update_judgement_status_details(id) {
@ -388,6 +405,7 @@ $.fn.uoj_highlight = function() {
return $(this).each(function() { return $(this).each(function() {
$(this).find("span.uoj-username").each(replaceWithHighlightUsername); $(this).find("span.uoj-username").each(replaceWithHighlightUsername);
$(this).find(".uoj-honor").uoj_honor(); $(this).find(".uoj-honor").uoj_honor();
$(this).find(".uoj-testcase").uoj_testcase();
$(this).find(".uoj-score").each(function() { $(this).find(".uoj-score").each(function() {
var score = parseInt($(this).text()); var score = parseInt($(this).text());
var maxscore = parseInt($(this).data('max')); var maxscore = parseInt($(this).data('max'));