]> www.fi.muni.cz Git - paste.git/commitdiff
Download link master
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 21 Apr 2022 14:30:53 +0000 (16:30 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 21 Apr 2022 14:42:29 +0000 (16:42 +0200)
paste.pl

index 285c34940b700ec8da83311e73197d6a05f3fcdb..3eb13882f26ee372d18f19cf0db5fa6e3e8dfead 100755 (executable)
--- a/paste.pl
+++ b/paste.pl
@@ -56,6 +56,13 @@ get '/<filename>.<ext>'
        return $c->reply->not_found
                if !defined $stat;
 
+       if (defined $c->param('download')) {
+               $c->res->headers->content_disposition(
+                       "attachment; filename=$fullname"
+               );
+               $c->reply->file($file);
+               return;
+       }
        $c->stash(mtime => POSIX::strftime('%Y-%m-%d %H:%M:%S',
                localtime($stat->mtime)));
        my $content = $file->slurp;
@@ -100,7 +107,9 @@ __DATA__
 
 <h1><tt><%= $filename%>.<%= $ext %></tt>
    <span class="unimportant">— <%= config->{appname} %></span><br/>
-<small class="unimportant">Created: <%= $mtime %></small></h1>
+<small class="unimportant">Created: <%= $mtime %>
+<%= link_to "Download" => url_for->query(download => 1), class => 'downl' %>
+</small></h1>
 <pre><code class="<%= $language %>"><%= $file_content %></code></pre>
 
 
@@ -179,6 +188,10 @@ __DATA__
       a {
         color: #90c0ff;
       }
+      a.downl {
+        display: inline-block;
+        float: right;
+      }
     </style>
     <title><%= config->{appname} %></title>
   </head>