X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FPlack%2FApp%2FGruntmaster.pm;h=31ea346f8f9d637d05ba29565b2108c6934b79a0;hb=7baee29b2642aabb77a24745dc8be86440c30a4f;hp=c7c6620ed9f52bfe4952b15ebad4d029cbba8a15;hpb=ea6cce4c6c69f605e069049df4ca72f08451ef95;p=plack-app-gruntmaster.git diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index c7c6620..31ea346 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -7,6 +7,7 @@ our $VERSION = '5999.000_001'; use Encode qw/encode decode/; use File::Slurp qw/read_file/; use JSON::MaybeXS qw/encode_json/; +use List::Util qw/min/; use PerlX::Maybe; use Scope::Upper qw/unwind SUB UP/; use Web::Simple; @@ -22,18 +23,24 @@ no warnings 'illegalproto'; use constant USER_REGEX => qr/^\w{2,20}$/a; use constant FORMAT_EXTENSION => { + BRAINFUCK => 'bf', C => 'c', CPP => 'cpp', + D => 'd', GCCGO => 'go', GOLANG => 'go', GOLFSCRIPT => 'gs', HASKELL => 'hs', - MONO => 'cs', JAVA => 'java', + JULIA => 'jl', + MONO => 'cs', + OCAML => 'ml', PASCAL => 'pas', PERL => 'pl', + PHP => 'php', PYTHON => 'py', RUBY => 'rb', + RUST => 'rs', SBCL => 'l', }; @@ -55,14 +62,14 @@ sub admin { remote_user && remote_user->{admin} } sub redirect { [301, ['X-Forever' => 1, 'Cache-Control' => 'public, max-age=86400', 'Location' => $_[0]], []] } sub reply { [200, ['Content-Type' => 'text/plain; charset=utf-8'], \@_] } sub response { - my ($template, $title, $params, $maxage) = @_; + my ($template, $title, $params, $maxage, $smaxage) = @_; unless ($params) { $params = $title; $title = 'No title'; } $params->{time} = time; $params->{args} = {%_}; - bless {template => $template, title => $title, params => $params, maxage => ($maxage // 3600)}, __PACKAGE__.'::Response' + bless {template => $template, title => $title, params => $params, maxage => ($maxage // 3600), maybe smaxage => $smaxage}, __PACKAGE__.'::Response' } sub forbid { @@ -97,7 +104,9 @@ sub dispatch_request{ response_filter { my ($r) = @_; return $r if ref $r ne 'Plack::App::Gruntmaster::Response'; - my @hdrs = ('X-Forever' => 1, 'Cache-Control' => "$privacy, max-age=$r->{maxage}"); + my $smaxage = $r->{smaxage} ? ", s-maxage=$r->{smaxage}" : ''; + my @hdrs = ('Cache-Control' => "$privacy$smaxage, max-age=$r->{maxage}"); + push @hdrs, 'X-Forever' => 1 unless $smaxage; push @hdrs, Vary => 'Authorization' if $privacy eq 'private'; return [200, ['Content-Type' => 'application/json; charset=utf-8', @hdrs], [encode_json $r->{params}]] if $format eq 'json'; my $ret = render $r->{template}, 'en', title => $r->{title}, %{$r->{params}}; @@ -106,7 +115,7 @@ sub dispatch_request{ }, sub (/st/:contest) { - my @pb = map { [$_->{id}, $_->{name}] } @{problem_list contest => $_{contest}}; + my @pb = map { [$_->{id}, $_->{name}] } sort { $a->{value} <=> $b->{value} } @{problem_list contest => $_{contest}}; response st => 'Standings', {problems => \@pb, st => standings $_{contest}}, 10 }, @@ -125,7 +134,13 @@ sub dispatch_request{ sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" }, sub (/us/) { response us => 'Users', {us => user_list} }, - sub (/ct/ + ?:owner~) { response ct => 'Contests', {ct => contest_list(%_)}, 300 }, + sub (/ct/ + ?:owner~) { + my $cts = contest_list(%_); + my $first_event = min + map ({ $_->{start} } grep { !$_->{started} } @$cts), + map ({ $_->{stop} } grep { $_->{started} && !$_->{finished}} @$cts); + response ct => 'Contests', {ct => $cts}, 300, $first_event ? ($first_event - time) : (); + }, sub (/log/ + ?:contest~&:owner~&:page~&:problem~&:private~&:result~) { forbid $_{private}; my ($jobs, $pageinfo) = job_list(%_); @@ -144,7 +159,10 @@ sub dispatch_request{ }, sub (/ct/:contest) { my $contest = contest_entry $_{contest}; - response ct_entry => $contest->{name}, $contest, 60 + my $smaxage; + $smaxage = $contest->{start} - time if !$contest->{started}; + $smaxage = $contest->{stop} - time if $contest->{started} && !$contest->{finished}; + response ct_entry => $contest->{name}, $contest, 60, $smaxage ? ($smaxage) : () }, sub (/log/:job) { my $job = job_entry $_{job};