X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FSubmit.pm;h=569fe9186f38c2cadff58d62af93767f43a4ce61;hb=6a9aaf149c09cd2e8ae1332e4f50abbb946870c2;hp=e6f44deebfcee2e889a78cd2f5d613b5ffec5da8;hpb=42546e6c1b709dc4c8d8e7048becc14278b6cdf0;p=gruntmaster-page.git diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index e6f44de..569fe91 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -1,56 +1,57 @@ 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 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'; + 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 > contest_end $contest); + return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; + return reply 'You must wait 30 seconds between jobs' unless time > lastjob ($r->user) + 30; + set_lastjob $r->user; + + local $Gruntmaster::Data::contest = $contest if $contest; + + my $job = push_job ( + date => time, + problem => $problem, + user => $r->user, + defined $private ? (private => $private) : (), + defined $contest ? (contest => $contest, private => 1) : (), + filesize => length $prog, + extension => FORMAT_EXTENSION->{$format}, + ); + + set_job_inmeta $job, { + files => { + prog => { + format => $format, + name => 'prog.' . FORMAT_EXTENSION->{$format}, + content => $prog, + } + } + }; + + $contest //= ''; + PUBLISH 'jobs', "$contest.$job"; + [303, [Location => $r->path =~ s,/pb/\w+/submit$,/log/,r], ['']] } 1