unload, etc, etctags/v1.0.0
@@ -68,6 +68,7 @@ func previewHandler(w http.ResponseWriter, r *http.Request) { | |||
contentType, contentLength, err := storage.Head(token, filename) | |||
if err != nil { | |||
http.Error(w, http.StatusText(404), 404) | |||
return | |||
} | |||
var templatePath string | |||
@@ -76,20 +77,29 @@ func previewHandler(w http.ResponseWriter, r *http.Request) { | |||
switch { | |||
case strings.HasPrefix(contentType, "image/"): | |||
templatePath = "static/download.image.html" | |||
case strings.HasPrefix(contentType, "text/x-markdown"): | |||
case strings.HasPrefix(contentType, "text/"): | |||
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/"): | |||
if strings.HasPrefix(contentType, "text/x-markdown") || strings.HasPrefix(contentType, "text/markdown") { | |||
output := blackfriday.MarkdownCommon(data) | |||
content = html_template.HTML(output) | |||
} else if strings.HasPrefix(contentType, "text/plain") { | |||
content = html_template.HTML(fmt.Sprintf("<pre>%s</pre>", data)) | |||
} else { | |||
content = html_template.HTML(data) | |||
} | |||
templatePath = "static/download.md.html" | |||
default: | |||
templatePath = "static/download.html" | |||
@@ -363,10 +373,17 @@ func zipHandler(w http.ResponseWriter, r *http.Request) { | |||
zw := zip.NewWriter(w) | |||
for _, key := range strings.Split(files, ",") { | |||
token := sanitize.Path(strings.Split(key, "/")[0]) | |||
if strings.HasPrefix(key, "/") { | |||
key = key[1:] | |||
} | |||
key = strings.Replace(key, "\\", "/", -1) | |||
token := strings.Split(key, "/")[0] | |||
filename := sanitize.Path(strings.Split(key, "/")[1]) | |||
reader, _, _, err := storage.Get(token, filename) | |||
if err != nil { | |||
if err.Error() == "The specified key does not exist." { | |||
http.Error(w, "File not found", 404) | |||
@@ -427,8 +444,14 @@ func tarGzHandler(w http.ResponseWriter, r *http.Request) { | |||
defer zw.Close() | |||
for _, key := range strings.Split(files, ",") { | |||
if strings.HasPrefix(key, "/") { | |||
key = key[1:] | |||
} | |||
key = strings.Replace(key, "\\", "/", -1) | |||
token := strings.Split(key, "/")[0] | |||
filename := strings.Split(key, "/")[1] | |||
filename := sanitize.Path(strings.Split(key, "/")[1]) | |||
reader, _, contentLength, err := storage.Get(token, filename) | |||
if err != nil { | |||
@@ -89,6 +89,8 @@ func main() { | |||
r.HandleFunc("/download/{token}/{filename}", getHandler).Methods("GET") | |||
r.HandleFunc("/{token}/{filename}", previewHandler).MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) bool { | |||
// The file will show a preview page when opening the link in browser directly or | |||
// from external link. Otherwise it will download the file immediatly. | |||
if !acceptsHtml(r.Header) { | |||
return false | |||
} | |||
@@ -98,11 +100,12 @@ func main() { | |||
u, err := url.Parse(r.Referer()) | |||
if err != nil { | |||
log.Fatal(err) | |||
return false | |||
return match | |||
} | |||
match = match || (u.Host == "transfersh.elasticbeanstalk.com") | |||
match = match || (u.Host == "jxm5d6emw5rknovg.onion") | |||
match = match || (u.Host == "transfer.sh") | |||
match = match || (u.Host == "127.0.0.1") | |||
return match | |||
@@ -59,6 +59,10 @@ | |||
<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> | |||
<a href="{{.Url}}" class="btn-cta btn"> download</i> </a> | |||
@@ -71,8 +75,56 @@ | |||
</div> | |||
</section> | |||
<script src="/scripts/main.js"></script> | |||
<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://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a> | |||
</p> | |||
</div> | |||
</footer> | |||
<a href="https://github.com/dutchcoders/transfer.sh/"> | |||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"> | |||
</a> | |||
<script> | |||
(function() { | |||
var uv = document.createElement('script'); | |||
uv.type = 'text/javascript'; | |||
uv.async = true; | |||
uv.src = '//widget.uservoice.com/5rkATbLIm8ClJQeOirOhFg.js'; | |||
var s = document.getElementsByTagName('script')[0]; | |||
s.parentNode.insertBefore(uv, s) | |||
})() | |||
</script> | |||
<!--[if lt IE 7]> | |||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |||
<![endif]--> | |||
<script> | |||
(function(b, o, i, l, e, r) { | |||
b.GoogleAnalyticsObject = l; | |||
b[l] || (b[l] = | |||
function() { | |||
(b[l].q = b[l].q || []).push(arguments) | |||
}); | |||
b[l].l = +new Date; | |||
e = o.createElement(i); | |||
r = o.getElementsByTagName(i)[0]; | |||
e.src = '//www.google-analytics.com/analytics.js'; | |||
r.parentNode.insertBefore(e, r) | |||
}(window, document, 'script', 'ga')); | |||
ga('create', 'UA-40833733-1', 'transfer.sh'); | |||
ga('send', 'pageview'); | |||
</script> | |||
<script src="/scripts/main.js"></script> | |||
@@ -16,7 +16,7 @@ | |||
<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> | |||
@@ -66,13 +66,9 @@ | |||
</div> | |||
<div id="terminal" class="terminal preview-image"> | |||
<img src="http://placehold.it/400x400" alt=""> | |||
<img src="{{.Url}}" width="400" alt=""> | |||
</div> | |||
</div> | |||
</div> | |||
<br/> | |||
<div> | |||
@@ -88,7 +84,55 @@ | |||
</div> | |||
</section> | |||
<script src="scripts/main.js"></script> | |||
<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://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a> | |||
</p> | |||
</div> | |||
</footer> | |||
<a href="https://github.com/dutchcoders/transfer.sh/"> | |||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"> | |||
</a> | |||
<script> | |||
(function() { | |||
var uv = document.createElement('script'); | |||
uv.type = 'text/javascript'; | |||
uv.async = true; | |||
uv.src = '//widget.uservoice.com/5rkATbLIm8ClJQeOirOhFg.js'; | |||
var s = document.getElementsByTagName('script')[0]; | |||
s.parentNode.insertBefore(uv, s) | |||
})() | |||
</script> | |||
<!--[if lt IE 7]> | |||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |||
<![endif]--> | |||
<script> | |||
(function(b, o, i, l, e, r) { | |||
b.GoogleAnalyticsObject = l; | |||
b[l] || (b[l] = | |||
function() { | |||
(b[l].q = b[l].q || []).push(arguments) | |||
}); | |||
b[l].l = +new Date; | |||
e = o.createElement(i); | |||
r = o.getElementsByTagName(i)[0]; | |||
e.src = '//www.google-analytics.com/analytics.js'; | |||
r.parentNode.insertBefore(e, r) | |||
}(window, document, 'script', 'ga')); | |||
ga('create', 'UA-40833733-1', 'transfer.sh'); | |||
ga('send', 'pageview'); | |||
</script> | |||
<script src="/scripts/main.js"></script> | |||
@@ -16,7 +16,7 @@ | |||
<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> | |||
@@ -55,13 +55,9 @@ | |||
<section id="home"> | |||
<div class="wrapper"> | |||
<h2> | |||
{{.Filename}}</h2> | |||
<h4> | |||
Type: <b>{{.ContentType}}</b></h4> | |||
<h4> | |||
Length: <b>{{.ContentLength}}</b> bytes</h4> | |||
<a href="{{.Url}}"></a> | |||
<h2>{{.Filename}}</h2> | |||
<h4>Type: <b>{{.ContentType}}</b></h4> | |||
<h4>Length: <b>{{.ContentLength}}</b> bytes</h4> | |||
<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"> | |||
@@ -117,23 +113,57 @@ | |||
ga('send', 'pageview'); | |||
</script> | |||
<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://blog.dutchcoders.io/" title="Dutch Coders">Dutch Coders</a> | |||
</p> | |||
</div> | |||
</footer> | |||
<a href="https://github.com/dutchcoders/transfer.sh/"> | |||
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"> | |||
</a> | |||
<script> | |||
(function() { | |||
var uv = document.createElement('script'); | |||
uv.type = 'text/javascript'; | |||
uv.async = true; | |||
uv.src = '//widget.uservoice.com/5rkATbLIm8ClJQeOirOhFg.js'; | |||
var s = document.getElementsByTagName('script')[0]; | |||
s.parentNode.insertBefore(uv, s) | |||
})() | |||
</script> | |||
<!--[if lt IE 7]> | |||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |||
<![endif]--> | |||
<script> | |||
(function(b, o, i, l, e, r) { | |||
b.GoogleAnalyticsObject = l; | |||
b[l] || (b[l] = | |||
function() { | |||
(b[l].q = b[l].q || []).push(arguments) | |||
}); | |||
b[l].l = +new Date; | |||
e = o.createElement(i); | |||
r = o.getElementsByTagName(i)[0]; | |||
e.src = '//www.google-analytics.com/analytics.js'; | |||
r.parentNode.insertBefore(e, r) | |||
}(window, document, 'script', 'ga')); | |||
ga('create', 'UA-40833733-1', 'transfer.sh'); | |||
ga('send', 'pageview'); | |||
</script> | |||
<script src="/scripts/main.js"></script> | |||
<script> | |||
var text = $('#md-preview').html(); | |||
var converter = new Showdown.converter(); | |||
var html = converter.makeHtml(text); | |||
$('#md-preview').empty(); | |||
$('#md-preview').append(html); | |||
</script> | |||
</body> | |||
</html> |
@@ -8,5 +8,5 @@ | |||
<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> |
@@ -1,2 +1,2 @@ | |||
<script src="scripts/main.js"></script> | |||
<script src="/scripts/main.js"></script> | |||
@@ -16,7 +16,7 @@ | |||
<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> | |||
@@ -30,6 +30,7 @@ func (s *LocalStorage) Head(token string, filename string) (contentType string, | |||
var fi os.FileInfo | |||
if fi, err = os.Lstat(path); err != nil { | |||
return | |||
} | |||
contentLength = uint64(fi.Size()) | |||
@@ -49,6 +50,7 @@ func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser, | |||
var fi os.FileInfo | |||
if fi, err = os.Lstat(path); err != nil { | |||
return | |||
} | |||
contentLength = uint64(fi.Size()) | |||
@@ -101,8 +103,16 @@ func (s *S3Storage) Head(token string, filename string) (contentType string, con | |||
// content type , content length | |||
response, err := s.bucket.Head(key, map[string][]string{}) | |||
contentType = "" | |||
if err != nil { | |||
return | |||
} | |||
contentType = response.Header.Get("Content-Type") | |||
contentLength, err = strconv.ParseUint(response.Header.Get("Content-Length"), 10, 0) | |||
if err != nil { | |||
return | |||
} | |||
return | |||
} | |||
@@ -112,8 +122,15 @@ func (s *S3Storage) Get(token string, filename string) (reader io.ReadCloser, co | |||
// content type , content length | |||
response, err := s.bucket.GetResponse(key) | |||
contentType = "" | |||
if err != nil { | |||
return | |||
} | |||
contentType = response.Header.Get("Content-Type") | |||
contentLength, err = strconv.ParseUint(response.Header.Get("Content-Length"), 10, 0) | |||
if err != nil { | |||
return | |||
} | |||
reader = response.Body | |||
return | |||
@@ -49,7 +49,8 @@ include "includes/head.html" | |||
</div> | |||
</section> | |||
include "includes/js.html" | |||
include "includes/footer.html" | |||
include "includes/js.html" | |||
@@ -40,13 +40,9 @@ include "includes/head.html" | |||
</div> | |||
<div id="terminal" class="terminal preview-image"> | |||
<img src="http://placehold.it/400x400" alt=""> | |||
<img src="{{.Url}}" width="400" alt=""> | |||
</div> | |||
</div> | |||
</div> | |||
<br/> | |||
<div> | |||
@@ -62,6 +58,7 @@ include "includes/head.html" | |||
</div> | |||
</section> | |||
include "includes/footer.html" | |||
include "includes/js.html" | |||
</body> | |||
@@ -29,19 +29,15 @@ include "includes/head.html" | |||
<section id="home"> | |||
<div class="wrapper"> | |||
<h2> | |||
{{.Filename}}</h2> | |||
<h4> | |||
Type: <b>{{.ContentType}}</b></h4> | |||
<h4> | |||
Length: <b>{{.ContentLength}}</b> bytes</h4> | |||
<a href="{{.Url}}"></a> | |||
<h2>{{.Filename}}</h2> | |||
<h4>Type: <b>{{.ContentType}}</b></h4> | |||
<h4>Length: <b>{{.ContentLength}}</b> bytes</h4> | |||
<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> | |||
@@ -91,20 +87,8 @@ include "includes/head.html" | |||
ga('send', 'pageview'); | |||
</script> | |||
include "includes/footer.html" | |||
include "includes/js.html" | |||
<script> | |||
var text = "# Markdown *works*."; | |||
var converter = new Showdown.converter(); | |||
var html = converter.makeHtml(text); | |||
$('#md-preview').append(html); | |||
</script> | |||
</body> | |||
</html> |
@@ -8,7 +8,7 @@ | |||
<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 --> | |||
<!-- build:js /scripts/vendor/modernizr.js --> | |||
<script src="bower_components/modernizr/modernizr.js"></script> | |||
<!-- endbuild --> | |||
</head> |
@@ -1,4 +1,4 @@ | |||
<!-- build:js scripts/main.js --> | |||
<!-- build:js /scripts/main.js --> | |||
<script src="bower_components/jquery/dist/jquery.js"></script> | |||
<script src="bower_components/uri.js/src/URI.min.js"></script> | |||
<script src="bower_components/bootstrap/js/transition.js"></script> | |||
@@ -18,10 +18,18 @@ $(document).ready(function() { | |||
(function() { | |||
var files = Array() | |||
var queue = Array() | |||
function upload(file) { | |||
$(window).bind('beforeunload', function(){ | |||
if (queue.length==0) | |||
return; | |||
return 'There are still ' + queue.length + 'files being uploaded.'; | |||
}); | |||
function upload(file) { | |||
$('.browse').addClass('uploading'); | |||
var li = $('<li style="clear:both;"/>'); | |||
li.append($('<div><div class="upload-progress"><span></span><div class="bar" style="width:0%;">####################################################</div></div><p>Uploading... ' + file.name + '</p></div>')); | |||
@@ -34,11 +42,6 @@ $(document).ready(function() { | |||
$('.upload-progress', $(li)).show(); | |||
$('.upload-progress .bar', $(li)).css('width', pc + "%"); | |||
$('.upload-progress span ').empty().append(pc + "%"); | |||
$(window).bind('beforeunload', function(){ | |||
return 'File are still uploading'; | |||
}); | |||
}, false); | |||
xhr.onreadystatechange = function(e) { | |||
@@ -52,8 +55,12 @@ $(document).ready(function() { | |||
$(li).html('<span>Error (' + xhr.status + ') during upload of file ' + file.name + '</span>'); | |||
} | |||
files.push(xhr.responseText.replace("https://transfer.sh/", "").replace("\n", "")); | |||
// files.push(URI(xhr.responseText).absoluteTo(location.href).toString()); | |||
var index = queue.indexOf(xhr); | |||
if (index > -1) { | |||
queue.splice(index, 1); | |||
} | |||
files.push(URI(xhr.responseText.replace("\n", "")).path()); | |||
$(".download-zip").attr("href", URI("(" + files.join(",") + ").zip").absoluteTo(location.href).toString()); | |||
$(".download-tar").attr("href", URI("(" + files.join(",") + ").tar.gz").absoluteTo(location.href).toString()); | |||
@@ -61,7 +68,9 @@ $(document).ready(function() { | |||
$(".all-files").addClass('show'); | |||
} | |||
}; | |||
// should queue all uploads. | |||
queue.push(xhr); | |||
// start upload | |||
xhr.open("PUT", '/' + file.name, true); | |||
@@ -84,7 +93,6 @@ $(document).ready(function() { | |||
var files = event.originalEvent.target.files || event.originalEvent.dataTransfer.files; | |||
$.each(files, function(index, file) { | |||
console.debug(file); | |||
upload(file); | |||
}); | |||
@@ -3,9 +3,7 @@ | |||
} | |||
#download { | |||
//padding-bottom: 200px; | |||
footer { | |||
position: absolute; | |||
bottom: 0; | |||
width: 100%; | |||
} | |||
@@ -90,4 +88,4 @@ padding: 20px; | |||
#md-preview { | |||
padding-bottom: 30px; | |||
} | |||
} |
@@ -6368,7 +6368,6 @@ blockquote.tweet-xl a { | |||
padding-bottom: 30px; | |||
} | |||
#download footer { | |||
position: absolute; | |||
bottom: 0; | |||
width: 100%; | |||
} | |||