Clean-up some stuff

This commit is contained in:
swagg boi 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};
# Set filename for right-click & save-as behavior
if ($self->stash('format') eq 'txt') {
if ($self->accepts(0, 'txt')) {
$self->res->headers->content_disposition(
"inline; filename=remark_${remark_id}.txt"
)

View file

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