commit bea0490e721964170d7cd143f98ab72bd8b6513e from: monaco via: GitHub date: Tue Jun 27 21:25:12 2023 UTC Update paste.pl Added Download feature and more ... commit - 421b4b6a3f248d5c963ae2317cefe4d62f6ff3ea commit + bea0490e721964170d7cd143f98ab72bd8b6513e blob - 668d13e4f859fc9a1a0e039ca53c507141d6f747 blob + 801a8c611328e45de419371a08cea2e1e27802c3 --- paste.pl +++ paste.pl @@ -29,7 +29,7 @@ post '/' => sub { write_file("pastes/$id.txt", $content); $c->redirect_to("/$id"); } else { - $c->render(text => "Invalid paste content"); + $c->render(template => 'invalid_content'); } }; @@ -43,7 +43,8 @@ get '/:id' => sub { $paste->{expires_human} = format_expires($paste->{expires}); $c->render(template => 'paste', paste => $paste); } else { - $c->render(text => "Paste not found"); + $c->res->code(404); + $c->render(template => 'invalid_link'); } }; @@ -57,10 +58,27 @@ get '/raw/:id' => sub { $c->res->headers->content_type('text/plain'); $c->render(text => $content); } else { - $c->render(text => "Paste not found"); + $c->res->code(404); + $c->render(template => 'invalid_link'); } }; +get '/download/:id' => sub { + my $c = shift; + my $id = $c->param('id'); + my $sth = $dbh->prepare("SELECT content FROM pastes WHERE id = ?"); + $sth->execute($id); + my ($content) = $sth->fetchrow_array; + if ($content) { + $c->res->headers->content_type('text/plain'); + $c->res->headers->content_disposition("attachment; filename=$id.txt"); + $c->render(text => $content); + } else { + $c->res->code(404); + $c->render(template => 'invalid_link'); + } +}; + # start the app app->start; @@ -81,16 +99,8 @@ __DATA__ @@ index.html.ep - - - - KISSmo Perl Version 1.1 stable +

KISSmo Perl Version 1.1 stable

@@ -146,16 +164,8 @@ __DATA__ @@ paste.html.ep - - - - Paste +

Paste

<%= $paste->{content} %>
RAW + Download

Expires: <%= $paste->{expires_human} %>