X-Git-Url: http://git.ieval.ro/?p=nethack-naodash.git;a=blobdiff_plain;f=lib%2FApp%2FWeb%2FNAOdash.pm;fp=lib%2FApp%2FWeb%2FNAOdash.pm;h=be36928bd3f0f61a3ea4fb8125162d270fd06747;hp=985aaccd5f3bf94be8816edd21e6e949cd35987e;hb=89ac7b44e4f5f82b7e540b2465fae331662f6f11;hpb=fd3d16b10354e3a3d10ac71d758fd6d6ee62fc0a diff --git a/lib/App/Web/NAOdash.pm b/lib/App/Web/NAOdash.pm index 985aacc..be36928 100644 --- a/lib/App/Web/NAOdash.pm +++ b/lib/App/Web/NAOdash.pm @@ -13,6 +13,7 @@ use File::Slurp; use HTML::TreeBuilder; use JSON::MaybeXS qw/encode_json/; use NetHack::NAOdash qw/naodash_user/; +use Plack::Request; my ($dash, $css, $css_hash); @@ -49,7 +50,7 @@ sub format_time { } sub make_html { - my ($name, $result) = @_; + my ($name, $query, $result) = @_; my @checks = @{$result->{checks}}; my %numbers = %{$result->{numbers}}; $numbers{totalrealtime} = format_time $numbers{totalrealtime}; @@ -70,6 +71,8 @@ sub make_html { warn "No element for check $id" unless $el; ## no critic (RequireCarping) $el->delete_content->push_content($num); } + my $ahref = $tree->look_down(href => "?$query"); + $ahref->replace_with(join '', $ahref->content_list) if $ahref; $tree->as_HTML; } @@ -87,12 +90,17 @@ sub reply { sub call { my ($self, $env) = @_; - return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $env->{PATH_INFO} =~ m{^/(\w+)$}; + my $req = Plack::Request->new($env); + return reply 400, 'Bad request: user contains characters outside [a-zA-Z0-9_]' unless $req->path =~ m{^/(\w+)$}; my $name = $1; - my $result = eval { naodash_user $name } or return reply 500, $@; + my %args = ( + include_versions => [$req->query_parameters->get_all('include_versions')], + exclude_versions => [$req->query_parameters->get_all('exclude_versions')], + ); + my $result = eval { naodash_user \%args, $name } or return reply 500, $@; return reply 200, encode_json($result), 'application/json' if $self->{json}; - return reply 200, make_html($name, $result), 'text/html'; + return reply 200, make_html($name, $req->query_string, $result), 'text/html'; } 1; @@ -124,6 +132,12 @@ It handles URLs of the form C, where I is a NAO username. It retrieves the xlogfile from NAO and returns the result of the analysis. +Two query parameters are accepted: include_versions and +exclude_versions, both of which can take multiple values by +specifiying them multiple times. They are passed directly to the +B function, see the documentation of L +for an explanation of their function. + The constructor takes a single named parameter, I, that is false by default. The result will be returned as HTML is I is false, as JSON if I is true.