From 62c0b9213bb2662a880291bff448537a8af13eed Mon Sep 17 00:00:00 2001 From: swaggboi Date: Thu, 24 Aug 2023 20:28:38 -0400 Subject: [PATCH] Set filename for right-click & save-as behavior --- lib/PostText/Controller/Remark.pm | 7 +++++++ lib/PostText/Controller/Thread.pm | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/PostText/Controller/Remark.pm b/lib/PostText/Controller/Remark.pm index 4b7f8c2..5061339 100644 --- a/lib/PostText/Controller/Remark.pm +++ b/lib/PostText/Controller/Remark.pm @@ -11,6 +11,13 @@ sub by_id($self) { $self->stash(status => 404, error => 'Remark not found 🤷') unless keys %{$remark}; + # Set filename for right-click & save-as behavior + if ($self->stash('format') eq 'txt') { + $self->res->headers->content_disposition( + "inline; filename=remark_${remark_id}.txt" + ) + } + $self->render; } diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index c910d95..5011098 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -75,6 +75,13 @@ sub by_id($self) { $self->stash(status => 404, error => 'Page not found 🕵️') unless scalar @{$remarks} || $this_page == $last_page; + # Set filename for right-click & save-as behavior + if ($self->stash('format') eq 'txt') { + $self->res->headers->content_disposition( + "inline; filename=thread_${thread_id}.txt" + ) + } + $self->render; }