]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Submit.pm
Merge branch 'master' into mindcoding
[gruntmaster-page.git] / lib / Gruntmaster / Page / Submit.pm
1 package Gruntmaster::Page::Submit;
2
3 use Gruntmaster::Page::Base;
4
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 };
14
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';
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
25 }
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});
32
33 db($env)->jobs->create({
34 defined $contest ? (contest => $contest) : (),
35 date => time,
36 extension => FORMAT_EXTENSION->{$format},
37 format => $format,
38 defined $private ? (private => $private) : (),
39 problem => $problem,
40 source => $prog,
41 owner => $r->user
42 });
43
44 $contest //= '';
45 #PUBLISH 'jobs', "$contest.$job";
46 [303, [Location => ($contest ? "/ct/$contest/log/" : '/log/')], ['']]
47 }
48
49 1
This page took 0.046053 seconds and 4 git commands to generate.