X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSubmit.pm;h=5f7d7279006a0d0804c04e28fd537537e6d07d8e;hb=a46fb222e6ce50102b7c61a95af435afc74f5e33;hp=a57b7b177b05d52f27e77eb0aa219f254f77a320;hpb=832cb45e325364ca1de645a2256efa69284fcf06;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index a57b7b1..5f7d727 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -1,56 +1,49 @@ package Gruntmaster::Page::Submit; -use 5.014000; -use strict; -use warnings; -use parent qw/Exporter/; -our @EXPORT_OK = qw/generate/; -our $VERSION = '0.001'; - -use constant FORMATS => [qw/CPP/]; -use constant TITLE => 'Submit job'; - -use Fcntl qw/:flock/; -use HTML::Template::Compiled; -use IO::File; -use YAML::Any qw/LoadFile/; -use Gruntmaster::Page::Common qw/header footer/; - -my %templates = ( - en => <<'HTML', -
-

- -

- -

- - -HTML -); - -$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; -$templates{$_} .= footer $_ for keys %templates; +use Gruntmaster::Page::Base; + +use constant FORMAT_EXTENSION => { + C => 'c', + CPP => 'cpp', + MONO => 'cs', + JAVA => 'java', + PASCAL => 'pas', + PERL => 'pl', + PYTHON => 'py', +}; sub generate{ - my $template = $templates{$_[1]}; - my $htc = HTML::Template::Compiled->new(scalarref => \$template); - IO::File->new('>meta.yml')->close unless -f 'meta.yml'; - flock my $metafh = IO::File->new(' $id, name => $meta->{name} } } ; - $htc->param(problems => \@problems); - $htc->param(formats => FORMATS); - $htc->output + my ($self, $frm, $env) = @_; + my $r = Plack::Request->new($env); + my ($problem, $format, $contest, $private, $prog) = map {scalar $r->param($_)} 'problem', 'prog_format', 'contest', 'private', 'source_code'; + $problem //= $env->{'gruntmaster.problem'}; + $contest //= $env->{'gruntmaster.contest'}; + my $upload = $r->upload('prog'); + if (defined $upload) { + my $temp = read_file $upload->path; + $prog = $temp if $temp + } + die if defined $contest && $contest !~ /^\w+$/ ; + die if defined $contest && (time > db($env)->contest($contest)->stop); + return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; + return reply 'Maximum source size is 10KB' if length $prog > 25 * 1024; + return reply 'You must wait 30 seconds between jobs' unless time > db($env)->user($r->user)->lastjob + 30; + db($env)->user($r->user)->update({lastjob => time}); + + db($env)->jobs->create({ + defined $contest ? (contest => $contest) : (), + date => time, + extension => FORMAT_EXTENSION->{$format}, + format => $format, + defined $private ? (private => $private) : (), + problem => $problem, + source => $prog, + owner => $r->user + }); + + $contest //= ''; + #PUBLISH 'jobs', "$contest.$job"; + [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']] } 1