diff --git a/app.pl b/app.pl index 85860fa..357aed1 100755 --- a/app.pl +++ b/app.pl @@ -5,9 +5,11 @@ use warnings; use FindBin qw($Bin); use lib "$Bin/lib"; use Data::Dumper; +use DBI; use Mojolicious::Lite; +my $dbh = DBI->connect("dbi:SQLite:dbname=pastes.db", "", "", {RaiseError => 1}); # hardcode some channels first my %channels = ( "freenode#perlbot" => "#perlbot (freenode)", @@ -16,31 +18,42 @@ my %channels = ( get '/' => sub { my $c = shift; - $c->stash({pastedata => q{}, channels => \%channels}); + $c->stash({pastedata => q{}, channels => \%channels, viewing => 0}); $c->render(template => "editor"); }; get '/pastebin' => sub {$_[0]->redirect_to('/')}; get '/paste' => sub {$_[0]->redirect_to('/')}; + post '/paste' => sub { my $c = shift; - $c->render(text => "post accepted!"); + + my @args = map {($c->param($_))} qw/paste user chan desc/; + + $dbh->do("INSERT INTO posts (paste, who, 'where', what, 'when') VALUES (?, ?, ?, ?, ?)", {}, @args, time()); + my $id = $dbh->last_insert_id('', '', 'posts', 'id'); + + $c->redirect_to('/pastebin/'.$id); + #$c->render(text => "post accepted! $id"); }; get '/pastebin/:pasteid' => sub { my $c = shift; my $pasteid = $c->param('pasteid'); - $c->stash({pastedata => q{ -use strict; -use warnings; + + my $row = $dbh->selectrow_hashref("SELECT * FROM posts WHERE id = ? LIMIT 1", {}, $pasteid); -use Data::Dumper; -use v5.24; + print Dumper($row); -say "Hello Perlbot"; - }, channels => \%channels}); + if ($row->{when}) { + $c->stash({pastedata => $row->{paste}, channels => \%channels, viewing => 1}); + $c->stash($row); + + $c->render(template => "editor"); + } else { +# 404 + } - $c->render(template => "editor"); }; app->start; @@ -73,7 +86,7 @@ __DATA__ display: none; } - #pastebin { + #paste { font-family: 'mono' } @@ -84,39 +97,53 @@ __DATA__
-