diff --git a/lib/CMTD/Main.pm b/lib/CMTD/Main.pm index b50d113..901bd19 100644 --- a/lib/CMTD/Main.pm +++ b/lib/CMTD/Main.pm @@ -24,7 +24,7 @@ sub captcha { } or do { chomp $@; $self->app->log->error("error when showing captcha: $@"); - $self->app->client_reply(500, "internal error"); + $self->client_reply(500, "internal error"); }; } @@ -33,7 +33,7 @@ sub c_list { my $ref = $self->referrer; unless ($ref and ref($ref) eq 'HASH') { - $self->app->client_reply(400, "can't detect referred page"); + $self->client_reply(400, "can't detect referred page"); return; } @@ -42,20 +42,21 @@ sub c_list { if ($site and ref($site) eq 'HASH') { my @cm = (); if (my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash})) { + $ref->{pid} = $pid; my @tm = $self->app->comments_by_pid($pid); # TODO: processing @cm = @tm; } $self->render(json => \@cm); } else { - $self->app->client_reply(400, "no such site"); + $self->client_reply(400, "no such site"); } 1; } or do { chomp $@; my $msg = sprintf "Error when listing comments for %s/%s: %s", $ref->{site}, $ref->{pid}, $@; $self->app->log->error($msg); - $self->app->client_reply(500, "internal error"); + $self->client_reply(500, "internal error"); }; } @@ -64,7 +65,7 @@ sub c_add { my $ref = $self->referrer; unless ($ref and ref($ref) eq 'HASH') { - $self->app->client_reply(400, "can't detect referred page"); + $self->client_reply(400, "can't detect referred page"); return; } @@ -79,25 +80,25 @@ sub c_add { } do {{ unless ($msg{text}) { - $self->app->client_reply(400, "empty message"); + $self->client_reply(400, "empty message"); last; } my $site = $self->app->site_by_name($ref->{site}); unless ($site and ref($site) eq 'HASH') { - $self->app->client_reply(400, "no such site"); + $self->client_reply(400, "no such site"); last; } if ($site->{captcha}) { unless ($cap{cid}) { - $self->app->client_reply(400, "missing captcha id"); + $self->client_reply(400, "missing captcha id"); last; } unless ($cap{code}) { - $self->app->client_reply(400, "missing captcha code"); + $self->client_reply(400, "missing captcha code"); last; } if (my $error = $self->app->captcha_solve($cap{id}, $cap{code})) { - $self->app->client_reply(400, $error); + $self->client_reply(400, $error); last; } } @@ -113,7 +114,7 @@ sub c_add { my $msg = sprintf "Error when listing comments for %s/%s: %s", $ref->{site}, $ref->{pid}, $@; $self->app->log->error($msg); - $self->app->client_reply(500, "internal error"); + $self->client_reply(500, "internal error"); }; }