From: Marius Gavrilescu Date: Sun, 4 Jan 2015 13:48:26 +0000 (+0200) Subject: Fix file uploads X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=0879466792e79a49331bf5f3328baae117aa3475;p=gruntmaster-page.git Fix file uploads --- diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 14e7987..da00862 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -199,16 +199,17 @@ sub dispatch_request{ reply 'Password changed successfully'; }, - sub (/action/submit + %:problem=&:contest~&:prog_format=&:source_code~ + *:prog~) { + sub (/action/submit + %:problem=&:contest~&:prog_format=&:source_code~ + *prog~) { + my (undef, undef, $prog) = @_; forbid !remote_user; return reply 'This contest has finished' if contest && contest->is_finished; return reply 'This contest has not yet started' if !admin && contest && contest->is_pending; - return reply 'Maximum source size is 10KB' if ($_{prog} ? $_{prog}->size : length $_{source_code}) > 10 * 1024; + return reply 'Maximum source size is 10KB' if ($prog ? $prog->size : length $_{source_code}) > 10 * 1024; return reply 'You must wait 30 seconds between jobs' if !admin && time <= remote_user->lastjob + 30; remote_user->update({lastjob => time}); - my $prog = $_{prog} ? read_file $_{prog}->path : $_{source_code}; - unlink $_{prog}->path if $_{prog}; + my $source = $prog ? read_file $prog->path : $_{source_code}; + unlink $prog->path if $prog; db->jobs->create({ maybe contest => $_{contest}, maybe private => problem->private, @@ -216,7 +217,7 @@ sub dispatch_request{ extension => FORMAT_EXTENSION->{$_{prog_format}}, format => $_{prog_format}, problem => $_{problem}, - source => $prog, + source => $source, owner => remote_user->id, });