1 package Gruntmaster
::Page
::Submit
;
3 use Gruntmaster
::Page
::Base
;
5 use constant FORMAT_EXTENSION
=> {
16 my ($self, $frm, $env) = @_;
17 my $r = Plack
::Request
->new($env);
18 my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code';
19 $problem //= $env->{'gruntmaster.problem'};
20 $contest //= $env->{'gruntmaster.contest'};
21 my $upload = $r->upload('prog');
22 if (defined $upload) {
23 my $temp = read_file
$upload->path;
24 $prog = $temp if $temp
26 die if defined $contest && $contest !~ /^\w+$/ ;
27 die if defined $contest && (time > db
($env)->contest($contest)->stop);
28 return reply
'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog;
29 return reply
'Maximum source size is 10KB' if length $prog > 25 * 1024;
30 return reply
'You must wait 30 seconds between jobs' unless time > db
($env)->user($r->user)->lastjob + 30;
31 db
($env)->user($r->user)->update({lastjob
=> time});
33 db
($env)->jobs->create({
34 defined $contest ?
(contest
=> $contest) : (),
36 extension
=> FORMAT_EXTENSION
->{$format},
38 defined $private ?
(private
=> $private) : (),
45 #PUBLISH 'jobs', "$contest.$job";
46 [303, [Location
=> ($contest ?
"/ct/$contest/log/" : '/log/')], ['']]