]>
Commit | Line | Data |
---|---|---|
42546e6c MG |
1 | package Gruntmaster::Page::Submit; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
8d29b3b1 | 6 | use Gruntmaster::Page::Base; |
bb95f538 | 7 | our @ISA = qw/Gruntmaster::Page::Base/; |
42546e6c MG |
8 | our $VERSION = '0.001'; |
9 | ||
8d29b3b1 MG |
10 | use Apache2::Authen::Passphrase qw/pwcheck pwset USER_REGEX/; |
11 | use File::Slurp qw/read_file/; | |
12 | use Plack::Request; | |
42546e6c | 13 | |
8d29b3b1 MG |
14 | use constant FORMAT_EXTENSION => { |
15 | C => 'c', | |
16 | CPP => 'cpp', | |
17 | MONO => 'cs', | |
18 | JAVA => 'java', | |
19 | PASCAL => 'pas', | |
20 | PERL => 'pl', | |
21 | PYTHON => 'py', | |
22 | }; | |
42546e6c | 23 | |
8d29b3b1 MG |
24 | sub generate{ |
25 | my ($self, $frm, $env) = @_; | |
26 | my $r = Plack::Request->new($env); | |
27 | my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code'; | |
28 | my $upload = $r->upload('prog'); | |
29 | if (defined $upload) { | |
95a9ad1b | 30 | my $temp = read_file $upload->path; |
8d29b3b1 MG |
31 | $prog = $temp if $temp |
32 | } | |
33 | die if defined $contest && $contest !~ /^\w+$/ ; | |
34 | die if defined $contest && (time > contest_end $contest); | |
35 | return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; | |
808ba435 | 36 | return reply 'Maximum source size is 10KB' if length $prog > 25 * 1024; |
1acbe467 MG |
37 | return reply 'You must wait 30 seconds between jobs' unless time > lastjob ($r->user) + 30; |
38 | set_lastjob $r->user; | |
42546e6c | 39 | |
3c53f795 | 40 | local $Gruntmaster::Data::contest = $contest if $contest; |
42546e6c | 41 | |
8d29b3b1 MG |
42 | my $job = push_job ( |
43 | date => time, | |
44 | problem => $problem, | |
45 | user => $r->user, | |
46 | defined $private ? (private => $private) : (), | |
47 | defined $contest ? (contest => $contest, private => 1) : (), | |
48 | filesize => length $prog, | |
49 | extension => FORMAT_EXTENSION->{$format}, | |
50 | ); | |
42546e6c | 51 | |
8d29b3b1 MG |
52 | set_job_inmeta $job, { |
53 | files => { | |
54 | prog => { | |
55 | format => $format, | |
56 | name => 'prog.' . FORMAT_EXTENSION->{$format}, | |
57 | content => $prog, | |
58 | } | |
59 | } | |
60 | }; | |
2b0036ac | 61 | |
8d29b3b1 MG |
62 | $contest //= ''; |
63 | PUBLISH 'jobs', "$contest.$job"; | |
64 | [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']] | |
42546e6c MG |
65 | } |
66 | ||
8d29b3b1 MG |
67 | sub variants{ [[reply => 1, undef, undef, undef, undef, undef]] } |
68 | ||
42546e6c | 69 | 1 |