]>
Commit | Line | Data |
---|---|---|
42546e6c MG |
1 | package Gruntmaster::Page::Submit; |
2 | ||
8d29b3b1 | 3 | use Gruntmaster::Page::Base; |
42546e6c | 4 | |
8d29b3b1 MG |
5 | use constant FORMAT_EXTENSION => { |
6 | C => 'c', | |
7 | CPP => 'cpp', | |
8 | MONO => 'cs', | |
9 | JAVA => 'java', | |
10 | PASCAL => 'pas', | |
11 | PERL => 'pl', | |
12 | PYTHON => 'py', | |
13 | }; | |
42546e6c | 14 | |
8d29b3b1 MG |
15 | sub generate{ |
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'; | |
a46fb222 MG |
19 | $problem //= $env->{'gruntmaster.problem'}; |
20 | $contest //= $env->{'gruntmaster.contest'}; | |
8d29b3b1 MG |
21 | my $upload = $r->upload('prog'); |
22 | if (defined $upload) { | |
95a9ad1b | 23 | my $temp = read_file $upload->path; |
8d29b3b1 MG |
24 | $prog = $temp if $temp |
25 | } | |
26 | die if defined $contest && $contest !~ /^\w+$/ ; | |
d3200993 | 27 | die if defined $contest && (time > db($env)->contest($contest)->stop); |
8d29b3b1 | 28 | return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; |
fcd3a29c | 29 | return reply 'Maximum source size is 10KB' if length $prog > 25 * 1024; |
d3200993 | 30 | return reply 'You must wait 30 seconds between jobs' unless time > db($env)->user($r->user)->lastjob + 30; |
a46fb222 | 31 | db($env)->user($r->user)->update({lastjob => time}); |
42546e6c | 32 | |
d3200993 MG |
33 | db($env)->jobs->create({ |
34 | defined $contest ? (contest => $contest) : (), | |
8d29b3b1 | 35 | date => time, |
8d29b3b1 | 36 | extension => FORMAT_EXTENSION->{$format}, |
d3200993 MG |
37 | format => $format, |
38 | defined $private ? (private => $private) : (), | |
a46fb222 | 39 | problem => $problem, |
d3200993 | 40 | source => $prog, |
a46fb222 | 41 | owner => $r->user |
d3200993 | 42 | }); |
2b0036ac | 43 | |
8d29b3b1 | 44 | $contest //= ''; |
d3200993 | 45 | #PUBLISH 'jobs', "$contest.$job"; |
7b1f7ff6 | 46 | [303, [Location => ($contest ? "/ct/$contest/log/" : '/log/')], ['']] |
42546e6c MG |
47 | } |
48 | ||
49 | 1 |