From 1ad1929a0e2c5aedeba3e768a147ddd4562e81cf Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 17 Sep 2015 00:52:10 +0200 Subject: [PATCH] Add file extension to view link --- Changes | 1 + lib/Lutim.pm | 6 +++++- lib/Lutim/Controller.pm | 6 +++++- templates/index.html.ep | 2 +- templates/partial/lutim.js.ep | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 6b267ae..7c20751 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,7 @@ Revision history for Lutim - Update twitter bootstrap - Add "Copy to clipboard" buttons to each link - Add "Copy all links" button + - Add file extension to view link - bugfixes 0.6 2014-10-03 diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 86283d0..5ad2ebc 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -333,10 +333,14 @@ sub startup { to('Controller#modify')-> name('modify'); - $r->get('/:short')-> + $r->get('/(:short).(:f)')-> to('Controller#short')-> name('short'); + $r->get('/:short')-> + to('Controller#short'); + $r->get('/:short/(:key).(:f)')-> + to('Controller#short'); $r->get('/:short/:key')-> to('Controller#short'); } diff --git a/lib/Lutim/Controller.pm b/lib/Lutim/Controller.pm index ae51fc9..2e74069 100644 --- a/lib/Lutim/Controller.pm +++ b/lib/Lutim/Controller.pm @@ -7,7 +7,7 @@ use DateTime; use Digest::file qw(digest_file_hex); use Text::Unidecode; use Data::Validate::URI qw(is_http_uri is_https_uri); -use File::MimeInfo::Magic; +use File::MimeInfo::Magic qw(mimetype extensions); use IO::Scalar; use Image::ExifTool; @@ -253,6 +253,8 @@ sub add { my $io_scalar = new IO::Scalar \$upload->slurp(); my $mediatype = mimetype($io_scalar); + my ($ext) = ($upload->filename =~ m/.*\.(.*)$/); + my $ip = $c->ip; my ($msg, $short, $real_short, $token, $thumb); @@ -375,6 +377,7 @@ sub add { short => $short, real_short => $real_short, token => $token, + ext => $ext || extensions($mediatype), thumb => $thumb }; } else { @@ -398,6 +401,7 @@ sub add { $c->stash(short => $short) if (defined($short)); $c->stash(real_short => $real_short); $c->stash(token => $token); + $c->stash(ext => $ext || extensions($mediatype)); $c->stash(thumb => $thumb); $c->stash(filename => $upload->filename); return $c->render( diff --git a/templates/index.html.ep b/templates/index.html.ep index 8a6448d..4ed77e7 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -29,7 +29,7 @@
- +
diff --git a/templates/partial/lutim.js.ep b/templates/partial/lutim.js.ep index 68a17b6..071d111 100644 --- a/templates/partial/lutim.js.ep +++ b/templates/partial/lutim.js.ep @@ -123,7 +123,7 @@ +tw_url(msg.short) +'' +'