1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut-pastebin synced 2025-06-07 06:06:23 -04:00

Merge branch 'master' of github.com:perlbot/perlbuut-pastebin

This commit is contained in:
Ryan Voots 2021-07-25 12:32:55 -04:00
commit 3bacf4671d
8 changed files with 33 additions and 110522 deletions

2
.gitignore vendored
View file

@ -7,3 +7,5 @@ asn.db
hypnotoad.pid
*.sql
*.script
.pls_cache/
.vstags

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "extern/ace-builds"]
path = extern/ace-builds
url = https://github.com/ajaxorg/ace-builds/
[submodule "extern/ace"]
path = extern/ace
url = https://github.com/ajaxorg/ace/

View file

@ -1,5 +1,5 @@
[database]
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes_dev"
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@192.168.32.1/perlbot_pastes_dev"
[mojolicious.hypnotoad]
listen=["http://localhost:3001"]

View file

@ -1,5 +1,5 @@
[database]
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@localhost/perlbot_pastes"
dsc="postgresql://perlbot_pastebin:wrorkEvopCagyadMoighinIgiloinnAl:drepHodNorchoibTessiraypGacWobjoolbyewd9OsofogerObhypBeurvackidnipBifreTwusGikghiavratuckTujtie@192.168.32.1/perlbot_pastes"
[mojolicious.hypnotoad]
listen=["http://localhost:3000"]

View file

@ -66,7 +66,7 @@ sub api_post_paste {
my @args = map {($c->param($_))} qw/paste username description channel expire language/;
my $id = $c->paste->insert_pastebin(@args, $c->remote_addr);
my ($slug, $id) = $c->paste->insert_pastebin(@args, $c->remote_addr);
my ($code, $who, $desc, $channel) = @args;
# TODO select which one based on config
@ -77,7 +77,7 @@ sub api_post_paste {
# } else {
if ($channel) { # TODO config for allowing announcements
my $words = $c->paste->banned_word_list_re;
my $url = $c->req->url->base()."/p/$id";
my $url = $c->req->url->base()."/p/$slug";
$url =~ s|http:|https:|;
unless ($code =~ $words || $who =~ $words || $desc =~ $words || $c->paste->is_banned_ip($c->remote_addr)) {
$c->perlbot->announce($channel, $who, substr($desc, 0, 40), $url);
@ -88,12 +88,12 @@ sub api_post_paste {
# }
$c->render(json => {
url => $c->req->url->base()."/p/$id", # TODO base url in config
id => $id,
url => $c->req->url->base()."/p/$slug", # TODO base url in config
id => $slug,
});
if ($c->param('redirect')) {
$c->redirect_to("/p/$id");
$c->redirect_to("/p/$slug");
}
};

View file

@ -83,7 +83,7 @@ sub api_post_paste {
my @args = map {($c->param($_))} qw/paste username description channel expire language/;
my $id = $c->paste->insert_pastebin(@args, $c->tx->remote_address);
my ($slug, $id) = $c->paste->insert_pastebin(@args, $c->tx->remote_address);
my ($code, $who, $desc, $channel) = @args;
# TODO select which one based on config
@ -94,7 +94,7 @@ sub api_post_paste {
# } else {
if ($channel) { # TODO config for allowing announcements
my $words = $c->paste->banned_word_list_re;
my $url = $c->req->url->base()."/p/$id";
my $url = $c->req->url->base()."/p/$slug";
$url =~ s|http:|https:|;
unless ($code =~ $words || $who =~ $words || $desc =~ $words || $c->paste->is_banned_ip($c->tx->remote_address)) {
$c->perlbot->announce($channel, $who, substr($desc, 0, 40), $url);
@ -103,12 +103,12 @@ sub api_post_paste {
# }
$c->render(json => {
url => $c->req->url->base()."/p/$id", # TODO base url in config
id => $id,
url => $c->req->url->base()."/p/$slug", # TODO base url in config
id => $slug,
});
if ($c->param('redirect')) {
$c->redirect_to("/p/$id");
$c->redirect_to("/p/$slug");
}
};

View file

@ -20,6 +20,20 @@ has 'pg' => sub {
has 'asndbh' => sub {DBI->connect("dbi:SQLite:dbname=asn.db", "", "", {RaiseError => 1, sqlite_unicode => 1})};
sub get_word_list {
my $self = shift;
my ($id) = @_;
my $word_counts = $self->pg->db->query("
WITH vector_decomp AS (
SELECT unnest(full_document_tsvector) AS vectors FROM posts WHERE id = ?
)
SELECT (vectors).lexeme as word, array_length((vectors).weights, 1) as word_count FROM vector_decomp
", $id)->hashes;
return $word_counts->each;
}
sub insert_pastebin {
my $self = shift;
my ($paste, $who, $what, $where, $expire, $lang, $ip) = @_;
@ -37,6 +51,7 @@ sub insert_pastebin {
ip => $ip
}, {returning => 'id'})->hash->{id};
# TODO this needs to retry when it fails.
my @chars = ('a'..'z', 1..9);
my $slug = join '', map {$chars[rand() *@chars]} 1..6;
@ -49,7 +64,7 @@ sub insert_pastebin {
}
);
return $slug;
return ($slug, $id);
}
sub get_paste {

File diff suppressed because it is too large Load diff