Clean-up some stuff

This commit is contained in:
swaggboi 2023-08-24 22:13:15 -04:00
parent 421e1f2169
commit 5e8bf0bf16
3 changed files with 19 additions and 2 deletions

View File

@ -12,7 +12,7 @@ sub by_id($self) {
unless keys %{$remark}; unless keys %{$remark};
# Set filename for right-click & save-as behavior # Set filename for right-click & save-as behavior
if ($self->stash('format') eq 'txt') { if ($self->accepts(0, 'txt')) {
$self->res->headers->content_disposition( $self->res->headers->content_disposition(
"inline; filename=remark_${remark_id}.txt" "inline; filename=remark_${remark_id}.txt"
) )

View File

@ -76,7 +76,7 @@ sub by_id($self) {
unless scalar @{$remarks} || $this_page == $last_page; unless scalar @{$remarks} || $this_page == $last_page;
# Set filename for right-click & save-as behavior # Set filename for right-click & save-as behavior
if ($self->stash('format') eq 'txt') { if ($self->accepts(0, 'txt')) {
$self->res->headers->content_disposition( $self->res->headers->content_disposition(
"inline; filename=thread_${thread_id}.txt" "inline; filename=thread_${thread_id}.txt"
) )

17
t/filename.t Normal file
View File

@ -0,0 +1,17 @@
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('PostText');
$t->get_ok('/thread/single/1.txt')->status_is(200)
->header_like('Content-Disposition' => qr/filename=thread_1\.txt/);
$t->get_ok('/thread/single/1')->status_is(200)
->header_unlike('Content-Disposition' => qr/filename=thread_1\.txt/);
$t->get_ok('/remark/single/1.txt')->status_is(200)
->header_like('Content-Disposition' => qr/filename=remark_1\.txt/);
$t->get_ok('/remark/single/1')->status_is(200)
->header_unlike('Content-Disposition' => qr/filename=remark_1\.txt/);
done_testing;