diff --git a/example_post_text.conf b/example_post_text.conf index 23d3648..21ef9a4 100644 --- a/example_post_text.conf +++ b/example_post_text.conf @@ -1,6 +1,7 @@ { - threads_per_page => 5, - remarks_per_page => 5, + threads_per_page => 5, + remarks_per_page => 5, + body_max_length => 8_000, secrets => ['t0p_s3cr3t'], development => { pg_string => diff --git a/lib/PostText/Controller/Remark.pm b/lib/PostText/Controller/Remark.pm index f433daf..4b7f8c2 100644 --- a/lib/PostText/Controller/Remark.pm +++ b/lib/PostText/Controller/Remark.pm @@ -15,15 +15,16 @@ sub by_id($self) { } sub create($self) { - my $thread_id = $self->param('thread_id'); - my $remark_id = $self->param('remark_id'); + my $thread_id = $self->param('thread_id'); + my $remark_id = $self->param('remark_id'); + my $body_limit = $self->config->{'body_max_length'} || 4_000; my ($v, $draft); $v = $self->validation if $self->req->method eq 'POST'; if ($v && $v->has_data) { - $v->required('author' )->size(1, 63); - $v->required('body' )->size(2, 4000); + $v->required('author' )->size(1, 63); + $v->required('body' )->size(2, $body_limit); $v->optional('bump' ); $v->optional('preview'); @@ -65,7 +66,8 @@ sub create($self) { $self->stash( thread => $thread, last_remark => $last_remark, - draft => $draft + draft => $draft, + body_limit => $body_limit ); $self->stash(status => 404, error => 'Thread not found 🤷') diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index 34f7e38..c910d95 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -5,14 +5,15 @@ use Date::Format; use XML::RSS; sub create($self) { + my $body_limit = $self->config->{'body_max_length'} || 4_000; my ($v, $draft); $v = $self->validation if $self->req->method eq 'POST'; if ($v && $v->has_data) { - $v->required('author' )->size(1, 63); - $v->required('title' )->size(1, 127); - $v->required('body' )->size(2, 4000); + $v->required('author' )->size(1, 63); + $v->required('title' )->size(1, 127); + $v->required('body' )->size(2, $body_limit); $v->optional('preview'); 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; } diff --git a/templates/remark/create.html.ep b/templates/remark/create.html.ep index 3a8edbe..55afb58 100644 --- a/templates/remark/create.html.ep +++ b/templates/remark/create.html.ep @@ -40,7 +40,7 @@ <%= label_for body => 'Text' %> <%= text_area body => ( id => 'body', - maxlength => 4000, + maxlength => $body_limit, minlength => 2, required => undef, rows => 6, diff --git a/templates/thread/create.html.ep b/templates/thread/create.html.ep index 734d194..11a19d7 100644 --- a/templates/thread/create.html.ep +++ b/templates/thread/create.html.ep @@ -51,7 +51,7 @@ <%= label_for body => 'Text' %> <%= text_area body => ( id => 'body', - maxlength => 4000, + maxlength => $body_limit, minlength => 2, required => undef, rows => 6