commit 0b30ea77e3a8f409ee3af21b0f831bafba76cc1d from: monaco via: GitHub date: Fri Jan 27 22:01:28 2023 UTC Fully featured paste commit - 0a4e6923a421893503926243a5ac7e8d10c0261e commit + 0b30ea77e3a8f409ee3af21b0f831bafba76cc1d blob - 1c137d2a2ef670287e420405b55277eab7f963e1 (mode 644) blob + /dev/null --- kpsm2.pl +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env perl - -use Mojolicious::Lite; -use DBI; -use Digest::SHA qw(sha1_hex); - -my $dbh = DBI->connect("dbi:SQLite:dbname=pastes.db", "", "", { RaiseError => 1 }); - -my $table_exists = $dbh->selectrow_array("SELECT name FROM sqlite_master WHERE type='table' AND name='pastes'"); -if (!$table_exists) { - $dbh->do("CREATE TABLE pastes (id TEXT PRIMARY KEY, content TEXT)"); -} - -get '/' => sub { - my $c = shift; - $c->render(template => 'index'); -}; - -post '/create' => sub { - my $c = shift; - my $content = $c->param('content'); - my $id = sha1_hex(time . $content); - $dbh->do("INSERT INTO pastes (id, content) VALUES (?, ?)", undef, $id, $content); - $c->redirect_to("/view/$id"); -}; - -get '/view/:id' => sub { - my $c = shift; - my $id = $c->param('id'); - my $content = $dbh->selectrow_array("SELECT content FROM pastes WHERE id = ?", undef, $id); - $c->render(text => $content); -}; - -get '/search' => sub { - my $c = shift; - my $query = $c->param('q'); - my $results = $dbh->selectall_arrayref("SELECT id FROM pastes WHERE content LIKE ?", { Slice => {} }, "%$query%"); - $c->render(template => 'search', results => $results); -}; - -app->start; -__DATA__ - -@@ index.html.ep - - - - Pastebin - - - -

Create a new paste

-
- - -
-

Search for a paste

-
- - -
- - - -@@ search.html.ep - - - - Pastebin - - - -

Search Results

-