]> www.fi.muni.cz Git - paste.git/blobdiff - paste.pl
Download link
[paste.git] / paste.pl
index 8103a94b435860acdd76c9239608dfec7999a978..3eb13882f26ee372d18f19cf0db5fa6e3e8dfead 100755 (executable)
--- a/paste.pl
+++ b/paste.pl
@@ -56,9 +56,18 @@ 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)));
-       $c->stash(file_content => $file->slurp);
+       my $content = $file->slurp;
+       $content = Encode::decode('utf-8', $content);
+       $c->stash(file_content => $content);
        my $lang = $c->param('ext');
 
        $c->stash(language => "language-$lang");
@@ -98,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>
 
 
@@ -164,9 +175,11 @@ __DATA__
         border-radius: .4rem;
       }
       pre code {
-        padding: 0;
+        padding: 1em;
         margin-left: 0;
         margin-right: 0;
+        background: black;
+        color: #aaa;
       }
       div.footer {
         color: #999;
@@ -175,6 +188,10 @@ __DATA__
       a {
         color: #90c0ff;
       }
+      a.downl {
+        display: inline-block;
+        float: right;
+      }
     </style>
     <title><%= config->{appname} %></title>
   </head>