mirror of
https://github.com/perlbot/perlbuut-pastebin
synced 2025-06-07 14:17:26 -04:00
Slightly different insert api for the models, make it easier to handle the spam in a bit
This commit is contained in:
parent
6febb70948
commit
3118a02162
6 changed files with 30 additions and 110521 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
||||||
[submodule "extern/ace-builds"]
|
[submodule "extern/ace-builds"]
|
||||||
path = extern/ace-builds
|
path = extern/ace-builds
|
||||||
url = https://github.com/ajaxorg/ace-builds/
|
url = https://github.com/ajaxorg/ace-builds/
|
||||||
|
[submodule "extern/ace"]
|
||||||
|
path = extern/ace
|
||||||
|
url = https://github.com/ajaxorg/ace/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[database]
|
[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]
|
[mojolicious.hypnotoad]
|
||||||
listen=["http://localhost:3001"]
|
listen=["http://localhost:3001"]
|
||||||
|
|
|
@ -66,7 +66,7 @@ sub api_post_paste {
|
||||||
|
|
||||||
my @args = map {($c->param($_))} qw/paste username description channel expire language/;
|
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;
|
my ($code, $who, $desc, $channel) = @args;
|
||||||
|
|
||||||
# TODO select which one based on config
|
# TODO select which one based on config
|
||||||
|
@ -77,7 +77,7 @@ sub api_post_paste {
|
||||||
# } else {
|
# } else {
|
||||||
if ($channel) { # TODO config for allowing announcements
|
if ($channel) { # TODO config for allowing announcements
|
||||||
my $words = $c->paste->banned_word_list_re;
|
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:|;
|
$url =~ s|http:|https:|;
|
||||||
unless ($code =~ $words || $who =~ $words || $desc =~ $words || $c->paste->is_banned_ip($c->remote_addr)) {
|
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);
|
$c->perlbot->announce($channel, $who, substr($desc, 0, 40), $url);
|
||||||
|
@ -88,12 +88,12 @@ sub api_post_paste {
|
||||||
# }
|
# }
|
||||||
|
|
||||||
$c->render(json => {
|
$c->render(json => {
|
||||||
url => $c->req->url->base()."/p/$id", # TODO base url in config
|
url => $c->req->url->base()."/p/$slug", # TODO base url in config
|
||||||
id => $id,
|
id => $slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($c->param('redirect')) {
|
if ($c->param('redirect')) {
|
||||||
$c->redirect_to("/p/$id");
|
$c->redirect_to("/p/$slug");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ sub api_post_paste {
|
||||||
|
|
||||||
my @args = map {($c->param($_))} qw/paste username description channel expire language/;
|
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;
|
my ($code, $who, $desc, $channel) = @args;
|
||||||
|
|
||||||
# TODO select which one based on config
|
# TODO select which one based on config
|
||||||
|
@ -94,7 +94,7 @@ sub api_post_paste {
|
||||||
# } else {
|
# } else {
|
||||||
if ($channel) { # TODO config for allowing announcements
|
if ($channel) { # TODO config for allowing announcements
|
||||||
my $words = $c->paste->banned_word_list_re;
|
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:|;
|
$url =~ s|http:|https:|;
|
||||||
unless ($code =~ $words || $who =~ $words || $desc =~ $words || $c->paste->is_banned_ip($c->tx->remote_address)) {
|
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);
|
$c->perlbot->announce($channel, $who, substr($desc, 0, 40), $url);
|
||||||
|
@ -103,12 +103,12 @@ sub api_post_paste {
|
||||||
# }
|
# }
|
||||||
|
|
||||||
$c->render(json => {
|
$c->render(json => {
|
||||||
url => $c->req->url->base()."/p/$id", # TODO base url in config
|
url => $c->req->url->base()."/p/$slug", # TODO base url in config
|
||||||
id => $id,
|
id => $slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($c->param('redirect')) {
|
if ($c->param('redirect')) {
|
||||||
$c->redirect_to("/p/$id");
|
$c->redirect_to("/p/$slug");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,20 @@ has 'pg' => sub {
|
||||||
|
|
||||||
has 'asndbh' => sub {DBI->connect("dbi:SQLite:dbname=asn.db", "", "", {RaiseError => 1, sqlite_unicode => 1})};
|
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 {
|
sub insert_pastebin {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($paste, $who, $what, $where, $expire, $lang, $ip) = @_;
|
my ($paste, $who, $what, $where, $expire, $lang, $ip) = @_;
|
||||||
|
@ -37,6 +51,7 @@ sub insert_pastebin {
|
||||||
ip => $ip
|
ip => $ip
|
||||||
}, {returning => 'id'})->hash->{id};
|
}, {returning => 'id'})->hash->{id};
|
||||||
|
|
||||||
|
|
||||||
# TODO this needs to retry when it fails.
|
# TODO this needs to retry when it fails.
|
||||||
my @chars = ('a'..'z', 1..9);
|
my @chars = ('a'..'z', 1..9);
|
||||||
my $slug = join '', map {$chars[rand() *@chars]} 1..6;
|
my $slug = join '', map {$chars[rand() *@chars]} 1..6;
|
||||||
|
@ -49,7 +64,7 @@ sub insert_pastebin {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return $slug;
|
return ($slug, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_paste {
|
sub get_paste {
|
||||||
|
|
110509
static/build-2017-10-09.log
110509
static/build-2017-10-09.log
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue