use warnings;
our $VERSION = '0.001';
-use constant FORMAT_EXTENSION => {
- CPP => 'cpp',
-};
-
use Apache2::Access;
use Apache2::AuthzCaps qw/hascaps/;
use Apache2::RequestRec;
use File::Basename qw/fileparse/;
use File::Temp qw/tempdir/;
use File::Copy qw/move/;
-use YAML::Any qw/LoadFile DumpFile/;
+use Gruntmaster::Data qw/contest_start contest_end push_job set_job_inmeta/;
+use Gruntmaster::Page::Log;
+use Redis;
+
+my $redis = Redis->new;
sub submit{
my $r = shift;
chdir $r->dir_config('root');
my $req = Apache2::Request->new($r);
- my ($problem, $format, $contest) = map {scalar $req->param($_)} 'problem', 'prog_format', 'contest';
- my $ext = FORMAT_EXTENSION->{$format};
- my $prog = $req->upload('prog');
- die if defined $contest && $contest !~ /^\w+$/;
-
- if (defined $contest) {
- my $meta = LoadFile "ct/$contest/meta.yml";
- die unless time >= $meta->{start} && time <= $meta->{end}
- }
-
- my $dir = tempdir;
- $prog->link("$dir/prog.$ext");
- DumpFile "$dir/meta.yml", {
- files => {
- prog => {
- format => $format,
- name => 'prog.cpp',
+ my ($problem, $format, $contest, $private) = map {scalar $req->param($_)} 'problem', 'prog_format', 'contest', 'private';
+ my $prog;
+ $req->upload('prog')->slurp($prog);
+ die if defined $contest && $contest !~ /^\w+$/ ;
+ die if defined $contest && (time < contest_start $contest || time > contest_end $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 => Gruntmaster::Page::Log::FORMAT_EXTENSION->{$format},
+ );
+
+ set_job_inmeta $job, {
+ files => {
+ prog => {
+ format => $format,
+ name => 'prog.' . Gruntmaster::Page::Log::FORMAT_EXTENSION->{$format},
+ content => $prog,
+ }
}
- },
- problem => $problem,
- user => $r->user,
- date => time,
- defined $contest ? (contest => $contest) : (),
};
- my $jobname = int rand 1_000_000_000;
- $jobname = int rand 1_000_000_000 while -d "jobs/$jobname";
- move $dir, "jobs/$jobname" or die $!;
-
+ $redis->publish('jobs', $job);
$r->print("Job submitted");
OK
}
+=begin comment
+
sub private{
my $r = shift;
my $dir = (fileparse $r->uri)[1];
DECLINED
}
+=end comment
+
+=cut
+
1;
__END__
# Below is stub documentation for your module. You'd better edit it!