working on preview functions

This commit is contained in:
Remco 2014-11-10 17:18:55 +01:00
parent 4f3347aaab
commit 01f8157187
20 changed files with 109 additions and 135 deletions

View file

@ -37,6 +37,7 @@ import (
"github.com/dutchcoders/go-clamd"
"github.com/gorilla/mux"
"github.com/kennygrant/sanitize"
"github.com/russross/blackfriday"
html_template "html/template"
"io"
"io/ioutil"
@ -58,23 +59,40 @@ func healthHandler(w http.ResponseWriter, r *http.Request) {
/* The preview handler will show a preview of the content for browsers (accept type text/html), and referer is not transfer.sh */
func previewHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("preview")
vars := mux.Vars(r)
token := vars["token"]
filename := vars["filename"]
reader, contentType, contentLength, err := storage.Get(token, filename)
contentType, contentLength, err := storage.Head(token, filename)
if err != nil {
http.Error(w, http.StatusText(404), 404)
}
reader.Close()
var templatePath string
var content html_template.HTML
templatePath := "static/download.html"
if strings.HasPrefix(contentType, "image") {
switch {
case strings.HasPrefix(contentType, "image/"):
templatePath = "static/download.image.html"
case strings.HasPrefix(contentType, "text/x-markdown"):
templatePath = "static/download.md.html"
var reader io.ReadCloser
if reader, _, _, err = storage.Get(token, filename); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
var data []byte
if data, err = ioutil.ReadAll(reader); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
output := blackfriday.MarkdownCommon(data)
content = html_template.HTML(output)
case strings.HasPrefix(contentType, "text/"):
templatePath = "static/download.md.html"
default:
templatePath = "static/download.html"
}
tmpl, err := html_template.ParseFiles(templatePath)
@ -86,11 +104,13 @@ func previewHandler(w http.ResponseWriter, r *http.Request) {
data := struct {
ContentType string
Content html_template.HTML
Filename string
Url string
ContentLength uint64
}{
contentType,
content,
filename,
r.URL.String(),
contentLength,

View file

@ -33,6 +33,7 @@ import (
"github.com/gorilla/mux"
"log"
"math/rand"
"mime"
"net/http"
"net/url"
"os"
@ -97,7 +98,6 @@ func main() {
match = match || (u.Host == "127.0.0.1")
log.Printf("%s %s match %s", r.Referer(), u.Host, match)
return match
}).Methods("GET")
@ -153,6 +153,8 @@ func main() {
log.Panic("Error while creating storage.")
}
mime.AddExtensionType(".md", "text/x-markdown")
log.Printf("Transfer.sh server started. :%v using temp folder: %s", *port, config.Temp)
log.Printf("---------------------------")

View file

@ -13,12 +13,13 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<script src="scripts/vendor/modernizr.js"></script>
<script src="/scripts/vendor/modernizr.js"></script>
</head>
<body id="download">
<script>
(function(i, s, o, g, r, a, m) {
@ -52,22 +53,6 @@
</div>
</div>
<div id="navigation">
<div class="wrapper">
<a href="/">
<h1>transfer.sh</h1>
</a>
<ul class="hidden-xs">
<li><a href="/">home</a>
</li>
<li><a href="/#samples">sample use cases</a>
</li>
<li><a href="/#contact">contact us</a>
</li>
</ul>
</div>
</div>
<section id="home">
<div class="wrapper">
@ -86,8 +71,9 @@
</div>
</section>
<script src="scripts/main.js"></script>
<script src="/scripts/main.js"></script>

View file

@ -13,12 +13,13 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<script src="scripts/vendor/modernizr.js"></script>
</head>
<body id="download">
<script>
(function(i, s, o, g, r, a, m) {
@ -52,21 +53,6 @@
</div>
</div>
<div id="navigation">
<div class="wrapper">
<a href="/">
<h1>transfer.sh</h1>
</a>
<ul class="hidden-xs">
<li><a href="/">home</a>
</li>
<li><a href="/#samples">sample use cases</a>
</li>
<li><a href="/#contact">contact us</a>
</li>
</ul>
</div>
</div>
<section id="home">
<div class="wrapper">
<br/>
@ -105,6 +91,7 @@
<script src="scripts/main.js"></script>
</body>
</html>

View file

@ -13,12 +13,13 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<script src="scripts/vendor/modernizr.js"></script>
</head>
<body id="download">
<script>
(function(i, s, o, g, r, a, m) {
@ -56,13 +57,17 @@
<div class="wrapper">
<h2>
{{.Filename}}</h2>
<h4>
Type: <b>{{.ContentType}}</b></h4>
<h4>
Length: <b>{{.ContentLength}}</b> bytes</h4>
<a href="{{.Url}}"></a>
<div class="row animated fadeInDown">
<div id="from-terminal" class=" box col-md-8 col-md-offset-2 col-xs-12">
<div class="terminal-top">
</div>
<div id="terminal" class="terminal">
<div id="md-preview"></div>
<div id="md-preview">{{.Content}}</div>
</div>
</div>
</div>
@ -113,15 +118,17 @@
</script>
<script src="scripts/main.js"></script>
<script src="/scripts/main.js"></script>
<script>
var text = "# Markdown *works*.";
var text = $('#md-preview').html();
var converter = new Showdown.converter();
var html = converter.makeHtml(text);
$('#md-preview').empty();
$('#md-preview').append(html);
</script>

View file

@ -1,7 +1,7 @@
<footer>
<div class="wrapper">
<img src="images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
<img src="/images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
</p>
</div>
</footer>
@ -44,4 +44,4 @@
</script>

View file

@ -5,8 +5,8 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<script src="scripts/vendor/modernizr.js"></script>
</head>
</head>

View file

@ -1,2 +1,2 @@
<script src="scripts/main.js"></script>

View file

@ -13,13 +13,14 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<script src="scripts/vendor/modernizr.js"></script>
</head>
<body>
<script>
@ -78,7 +79,8 @@
<code>
<br>
<span class="code-title"># Upload from web</span>
<br>Drag your files here, or <a class="browse" href="#"> click to browse.</a>
<br>Drag your files here, or <a class="browse" href="#"> click to browse. <br/></a>
</code>
<input type="file" multiple="multiple" style='display: none;' />
<ul class='queue'>
@ -284,7 +286,7 @@
<br>
<br>
<iframe src="http://ghbtns.com/github-btn.html?user=dutchcoders&repo=transfer.sh&type=follow&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="300" height="50"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=dutchcoders&repo=transfer.sh&type=follow&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="250" height="50"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=dutchcoders&repo=transfer.sh&type=watch&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="200" height="50"></iframe>
</div>
</section>
@ -294,23 +296,29 @@
<div class="row">
<div class="col-md-8 col-md-offset-2 col-xs-12">
<blockquote class="twitter-tweet tweet-xl" lang="en">
<img class="twitter-profile" src="images/reviews/dave.jpg" alt="">
<a href="https://twitter.com/FloifyDave/status/517383101425516544">
<img class="twitter-profile" src="images/reviews/dave.jpg" alt="">
</a>
<p><a href="https://twitter.com/dutchcoders">@dutchcoders</a> Thanks for transfer.sh. Just used it for a production purpose for a customer. So great, so easy, so https. :)</p>
<a href="https://twitter.com/FloifyDave/status/517383101425516544">
&mdash; Dave Sims (@FloifyDave)</a>
&mdash; Dave Sims (@FloifyDave)</a>
</blockquote>
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<img class="twitter-profile" src="images/reviews/kareem.jpg" alt="">
<a href="https://twitter.com/kareemk/status/517029789191118849">
<img class="twitter-profile" src="images/reviews/kareem.jpg" alt="">
</a>
<p><a href="https://twitter.com/dutchcoders">@dutchcoders</a> love transfer.sh! any change we can *pay* for a self-hosted version?</p><a href="https://twitter.com/kareemk/status/517029789191118849">&mdash; Kareem Kouddous (@kareemk) </a>
</blockquote>
</div>
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<img class="twitter-profile" src="images/reviews/pg.jpeg" alt="">
<a href="https://twitter.com/drakpz/status/517008058841829376">
<img class="twitter-profile" src="images/reviews/pg.jpeg" alt="">
</a>
<p><a href="http://t.co/JomAmqWYEB">http://t.co/JomAmqWYEB</a> by <a href="https://twitter.com/dutchcoders">@dutchcoders</a> is pure awesomeness! any chance of source on github? :-)</p><a href="https://twitter.com/drakpz/status/517008058841829376">&mdash; PJ Spagnolatti (@drakpz)</a>
</blockquote>
</div>
@ -318,14 +326,18 @@
<div class="row">
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<img class="twitter-profile" src="images/reviews/jacob.jpg" alt="">
<a href="https://twitter.com/jacoblindgren11/status/516975006501203968">
<img class="twitter-profile" src="images/reviews/jacob.jpg" alt="">
</a>
<p>Love transfer.sh! Will be using it from now on! Thanks for the amazing service we can use from the CLI <a href="https://twitter.com/dutchcoders">@dutchcoders</a>
</p><a href="https://twitter.com/jacoblindgren11/status/516975006501203968">&mdash; Jacob Lindgren (@jacoblindgren11) </a>
</blockquote>
</div>
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<img class="twitter-profile" src="images/reviews/lars.jpg" alt="">
<a href="https://twitter.com/arvestad/status/519507976491499521">
<img class="twitter-profile" src="images/reviews/lars.jpg" alt="">
</a>
<p>transfer.sh is my latest fav service! Try simple command-line and web file sharing! <a href="https://t.co/FSrsb1JKJd">https://t.co/FSrsb1JKJd</a>&#10;Thanks <a href="https://twitter.com/dutchcoders">@dutchcoders</a> !</p> <a href="https://twitter.com/arvestad/status/519507976491499521">&mdash; Lars Arvestad (@arvestad)</a>
</blockquote>
</div>
@ -333,8 +345,6 @@
</div>
</section>
<section id="share">
<div class="wrapper">
<h2>Share the love</h2>
@ -379,8 +389,8 @@
<footer>
<div class="wrapper">
<img src="images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
<img src="/images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
</p>
</div>
</footer>
@ -425,11 +435,13 @@
<script src="scripts/main.js"></script>
<script src="/scripts/main.js"></script>
</body>

File diff suppressed because one or more lines are too long

View file

@ -123,8 +123,8 @@
<script src="bower_components/uri.js/src/URI.min.js"></script>
<script src="bower_components/bootstrap/js/transition.js"></script>
<script src="bower_components/bootstrap/js/collapse.js"></script>
<script src="scripts/showdown.js"></script>
<script src="scripts/main.js"></script>
<script src="/scripts/showdown.js"></script>
<script src="/scripts/main.js"></script>
<!-- endbuild -->
<script>

View file

@ -33,6 +33,10 @@ include "includes/head.html"
<br/>
<h2>
{{.Filename}}</h2>
<h4>
Type: <b>{{.ContentType}}</b></h4>
<h4>
Length: <b>{{.ContentLength}}</b> bytes</h4>
<div>
<a href="#" id="copy-link-btn" class="btn-cta btn">copy link</a> &nbsp;&nbsp;
<a href="{{.Url}}" class="btn-cta btn"> download</i> </a>

View file

@ -31,6 +31,10 @@ include "includes/head.html"
<div class="wrapper">
<h2>
{{.Filename}}</h2>
<h4>
Type: <b>{{.ContentType}}</b></h4>
<h4>
Length: <b>{{.ContentLength}}</b> bytes</h4>
<a href="{{.Url}}"></a>
<div class="row animated fadeInDown">
<div id="from-terminal" class=" box col-md-8 col-md-offset-2 col-xs-12">

View file

@ -1,7 +1,7 @@
<footer>
<div class="wrapper">
<img src="images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
<img src="/images/Logo-orange.png" alt="Founded in Holland">
<p>Made with <i class="icon-heart"></i> by <a href="http://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a>
</p>
</div>
</footer>
@ -44,4 +44,4 @@
</script>

View file

@ -5,10 +5,10 @@
<meta name="description" content="Easy and fast file sharing from the command-line.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="/styles/main.css">
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:100,200,300' rel='stylesheet' type='text/css'>
<link href='//fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'>
<!-- build:js scripts/vendor/modernizr.js -->
<script src="bower_components/modernizr/modernizr.js"></script>
<!-- endbuild -->
</head>
</head>

View file

@ -3,7 +3,7 @@
<script src="bower_components/uri.js/src/URI.min.js"></script>
<script src="bower_components/bootstrap/js/transition.js"></script>
<script src="bower_components/bootstrap/js/collapse.js"></script>
<script src="scripts/showdown.js"></script>
<script src="scripts/main.js"></script>
<script src="/scripts/showdown.js"></script>
<script src="/scripts/main.js"></script>
<!-- endbuild -->

View file

@ -4,7 +4,8 @@
overlay = document.getElementById("overlay");
var url = "http://url"
copylinkbtn.addEventListener("click", function() {
copylinkbtn.addEventListener("click", function(e) {
e.preventDefault();
var error = document.getElementsByClassName('error');
@ -17,10 +18,13 @@
copylink.children[1].value = url;
copylink.children[1].focus();
copylink.children[1].select();
return (false);
}, false);
overlay.addEventListener("click", function() {
overlay.addEventListener("click", function(e) {
e.preventDefault();
document.body.className = '';
return (false);
}, false);
copylink.children[2].addEventListener("keydown", function(e) {
@ -54,4 +58,4 @@
}
}
}, false);
})();
})();

View file

@ -81,60 +81,7 @@
background: url(../images/terminal-top.svg);
background-repeat: no-repeat;
background-size: cover;
height: 30px;<section id="reviews">
<div class="wrapper">
<div class="row">
<div class="col-md-8 col-md-offset-2 col-xs-12">
<blockquote class="twitter-tweet tweet-xl" lang="en">
<a href="https://twitter.com/FloifyDave/status/517383101425516544">
<img class="twitter-profile" src="images/reviews/dave.jpg" alt="">
</a>
<p><a href="https://twitter.com/dutchcoders">@dutchcoders</a> Thanks for transfer.sh. Just used it for a production purpose for a customer. So great, so easy, so https. :)</p>
<a href="https://twitter.com/FloifyDave/status/517383101425516544">
&mdash; Dave Sims (@FloifyDave)</a>
</blockquote>
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<a href="https://twitter.com/kareemk/status/517029789191118849">
<img class="twitter-profile" src="images/reviews/kareem.jpg" alt="">
</a>
<p><a href="https://twitter.com/dutchcoders">@dutchcoders</a> love transfer.sh! any change we can *pay* for a self-hosted version?</p><a href="https://twitter.com/kareemk/status/517029789191118849">&mdash; Kareem Kouddous (@kareemk) </a>
</blockquote>
</div>
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<a href="https://twitter.com/drakpz/status/517008058841829376">
<img class="twitter-profile" src="images/reviews/pg.jpeg" alt="">
</a>
<p><a href="http://t.co/JomAmqWYEB">http://t.co/JomAmqWYEB</a> by <a href="https://twitter.com/dutchcoders">@dutchcoders</a> is pure awesomeness! any chance of source on github? :-)</p><a href="https://twitter.com/drakpz/status/517008058841829376">&mdash; PJ Spagnolatti (@drakpz)</a>
</blockquote>
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<a href="https://twitter.com/jacoblindgren11/status/516975006501203968">
<img class="twitter-profile" src="images/reviews/jacob.jpg" alt="">
</a>
<p>Love transfer.sh! Will be using it from now on! Thanks for the amazing service we can use from the CLI <a href="https://twitter.com/dutchcoders">@dutchcoders</a>
</p><a href="https://twitter.com/jacoblindgren11/status/516975006501203968">&mdash; Jacob Lindgren (@jacoblindgren11) </a>
</blockquote>
</div>
<div class="col-md-6 col-xs-12">
<blockquote class="twitter-tweet" lang="en">
<a href="https://twitter.com/arvestad/status/519507976491499521">
<img class="twitter-profile" src="images/reviews/lars.jpg" alt="">
</a>
<p>transfer.sh is my latest fav service! Try simple command-line and web file sharing! <a href="https://t.co/FSrsb1JKJd">https://t.co/FSrsb1JKJd</a>&#10;Thanks <a href="https://twitter.com/dutchcoders">@dutchcoders</a> !</p> <a href="https://twitter.com/arvestad/status/519507976491499521">&mdash; Lars Arvestad (@arvestad)</a>
</blockquote>
</div>
</div>
</div>
</section>
height: 30px;
}
.upload-progress {

View file

@ -6106,6 +6106,7 @@ a:hover {
}
.upload-progress {
max-width: 80%;
padding-top: 4px;
}
.upload-progress .bar {
word-wrap: normal;

File diff suppressed because one or more lines are too long