Make max post length configurable

This commit is contained in:
swagg boi 2023-08-24 20:00:24 -04:00
parent f3edd88ee7
commit bb2ce292ed
5 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,7 @@
{ {
threads_per_page => 5, threads_per_page => 5,
remarks_per_page => 5, remarks_per_page => 5,
body_max_length => 8_000,
secrets => ['t0p_s3cr3t'], secrets => ['t0p_s3cr3t'],
development => { development => {
pg_string => pg_string =>

View file

@ -15,15 +15,16 @@ sub by_id($self) {
} }
sub create($self) { sub create($self) {
my $thread_id = $self->param('thread_id'); my $thread_id = $self->param('thread_id');
my $remark_id = $self->param('remark_id'); my $remark_id = $self->param('remark_id');
my $body_limit = $self->config->{'body_max_length'} || 4_000;
my ($v, $draft); my ($v, $draft);
$v = $self->validation if $self->req->method eq 'POST'; $v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) { if ($v && $v->has_data) {
$v->required('author' )->size(1, 63); $v->required('author' )->size(1, 63);
$v->required('body' )->size(2, 4000); $v->required('body' )->size(2, $body_limit);
$v->optional('bump' ); $v->optional('bump' );
$v->optional('preview'); $v->optional('preview');
@ -65,7 +66,8 @@ sub create($self) {
$self->stash( $self->stash(
thread => $thread, thread => $thread,
last_remark => $last_remark, last_remark => $last_remark,
draft => $draft draft => $draft,
body_limit => $body_limit
); );
$self->stash(status => 404, error => 'Thread not found 🤷') $self->stash(status => 404, error => 'Thread not found 🤷')

View file

@ -5,14 +5,15 @@ use Date::Format;
use XML::RSS; use XML::RSS;
sub create($self) { sub create($self) {
my $body_limit = $self->config->{'body_max_length'} || 4_000;
my ($v, $draft); my ($v, $draft);
$v = $self->validation if $self->req->method eq 'POST'; $v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) { if ($v && $v->has_data) {
$v->required('author' )->size(1, 63); $v->required('author' )->size(1, 63);
$v->required('title' )->size(1, 127); $v->required('title' )->size(1, 127);
$v->required('body' )->size(2, 4000); $v->required('body' )->size(2, $body_limit);
$v->optional('preview'); $v->optional('preview');
if ($v->has_error) { if ($v->has_error) {
@ -42,7 +43,10 @@ sub create($self) {
} }
} }
$self->stash(draft => $draft); $self->stash(
draft => $draft,
body_limit => $body_limit
);
return $self->render; return $self->render;
} }

View file

@ -40,7 +40,7 @@
<%= label_for body => 'Text' %> <%= label_for body => 'Text' %>
<%= text_area body => ( <%= text_area body => (
id => 'body', id => 'body',
maxlength => 4000, maxlength => $body_limit,
minlength => 2, minlength => 2,
required => undef, required => undef,
rows => 6, rows => 6,

View file

@ -51,7 +51,7 @@
<%= label_for body => 'Text' %> <%= label_for body => 'Text' %>
<%= text_area body => ( <%= text_area body => (
id => 'body', id => 'body',
maxlength => 4000, maxlength => $body_limit,
minlength => 2, minlength => 2,
required => undef, required => undef,
rows => 6 rows => 6