2013-02-09 05:11:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-02-12 15:21:25 +00:00
|
|
|
//"html/template"
|
|
|
|
"text/template"
|
2013-02-09 05:11:52 +00:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2013-02-11 19:27:38 +00:00
|
|
|
var emptyInterface interface{}
|
|
|
|
|
2013-02-12 15:21:25 +00:00
|
|
|
|
2013-02-11 19:27:38 +00:00
|
|
|
var headTemplate = template.Must(template.New("head").Parse(headTemplateHTML))
|
|
|
|
var headTemplateHTML = `
|
2013-02-09 05:11:52 +00:00
|
|
|
<html>
|
|
|
|
<head>
|
2013-02-12 15:21:25 +00:00
|
|
|
<link href="/assets/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
|
2013-02-11 19:27:38 +00:00
|
|
|
<title>{{.title}}</title>
|
2013-02-09 05:11:52 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
2013-02-11 19:27:38 +00:00
|
|
|
`
|
2013-02-09 05:11:52 +00:00
|
|
|
|
2013-02-12 15:21:25 +00:00
|
|
|
var navbarTemplate = template.Must(template.New("navbar").Parse(navbarTemplateHTML))
|
|
|
|
var navbarTemplateHTML = `
|
|
|
|
<div class="navbar navbar-inverse navbar-fixed-top">
|
|
|
|
<div class="navbar-inner">
|
|
|
|
<div class="container-fluid">
|
|
|
|
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
|
|
|
<span class="icon-bar"></span>
|
|
|
|
<span class="icon-bar"></span>
|
|
|
|
<span class="icon-bar"></span>
|
|
|
|
</a>
|
|
|
|
<a class="brand" href="/">filesrv</a>
|
|
|
|
<div class="nav-collapse collapse">
|
|
|
|
<p class="navbar-text pull-right">
|
|
|
|
</p>
|
|
|
|
<ul class="nav">
|
|
|
|
<li><a href="/">Home</a></li>
|
|
|
|
<li><a href="/upload">Upload</a></li>
|
|
|
|
<li><a href="/urlie">URLie</a></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
`
|
|
|
|
var containerBeginTemplate = template.Must(template.New("containerBegin").Parse(containerBeginTemplateHTML))
|
|
|
|
var containerBeginTemplateHTML = `
|
|
|
|
<div class="container-fluid">
|
|
|
|
<hr>
|
|
|
|
<hr>
|
|
|
|
<div class="row-fluid">
|
|
|
|
`
|
|
|
|
|
2013-02-11 19:27:38 +00:00
|
|
|
var tailTemplate = template.Must(template.New("tail").Parse(tailTemplateHTML))
|
|
|
|
var tailTemplateHTML = `
|
2013-02-12 15:21:25 +00:00
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
</div>
|
2013-02-11 19:27:38 +00:00
|
|
|
{{if .}}
|
|
|
|
<footer>{{.footer}}</footer>
|
|
|
|
{{end}}
|
2013-02-09 05:11:52 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
2013-02-11 19:27:38 +00:00
|
|
|
|
|
|
|
var formFileUploadTemplate = template.Must(template.New("formFileUpload").Parse(formFileUploadTemplateHTML))
|
|
|
|
var formFileUploadTemplateHTML = `
|
2013-02-12 15:21:25 +00:00
|
|
|
<div class="span9">
|
|
|
|
<div class="hero-unit">
|
|
|
|
<form enctype="multipart/form-data" action="/upload" method="POST">
|
|
|
|
<table>
|
|
|
|
<td>
|
|
|
|
<tr>
|
|
|
|
<input type="file" name="filename" placeholder="filename"> <input type="text" name="keywords" placeholder="keywords">
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<input type="submit" value="Upload File"><br/>
|
|
|
|
</tr>
|
|
|
|
</td>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
</div>{{/* hero-unit */}}
|
|
|
|
</div>{{/* span9 */}}
|
2013-02-11 19:27:38 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
var listTemplate = template.Must(template.New("list").Parse(listTemplateHTML))
|
|
|
|
var listTemplateHTML = `
|
|
|
|
{{if .}}
|
|
|
|
<ul>
|
|
|
|
{{range .}}
|
2013-02-12 15:21:25 +00:00
|
|
|
<li><a href="/f/{{.Filename}}">{{.Filename}}</a>
|
|
|
|
[keywords:{{range $key := .Metadata.Keywords}} <a href="/k/{{$key}}">{{$key}}</a>{{end}}]
|
|
|
|
[md5: <a href="/md5/{{.Md5}}">{{.Md5 | printf "%8.8s"}}...</a>]</li>
|
2013-02-11 19:27:38 +00:00
|
|
|
{{end}}
|
|
|
|
</ul>
|
2013-02-12 15:21:25 +00:00
|
|
|
{{end}}
|
2013-02-11 19:27:38 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func UploadPage(w io.Writer) (err error) {
|
|
|
|
err = headTemplate.Execute(w, map[string]string{"title" : "FileSrv :: Upload"})
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-12 15:21:25 +00:00
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-11 19:27:38 +00:00
|
|
|
err = formFileUploadTemplate.Execute(w, &emptyInterface)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-12 15:21:25 +00:00
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer" : ""})
|
2013-02-11 19:27:38 +00:00
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListFilesPage(w io.Writer, files []File) (err error) {
|
|
|
|
err = headTemplate.Execute(w, map[string]string{"title" : "FileSrv"})
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-12 15:21:25 +00:00
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-11 19:27:38 +00:00
|
|
|
err = listTemplate.Execute(w, files)
|
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-12 15:21:25 +00:00
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer" : ""})
|
2013-02-09 05:11:52 +00:00
|
|
|
if (err != nil) {
|
|
|
|
return err
|
|
|
|
}
|
2013-02-11 19:27:38 +00:00
|
|
|
return
|
2013-02-09 05:11:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 15:21:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bootstrap Responsive v2.2.2
|
|
|
|
// Copyright 2012 Twitter, Inc
|
|
|
|
// Licensed under the Apache License v2.0
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Designed and built with all the love in the world @twitter by @mdo and @fat.
|
|
|
|
var bootstrapCSS = `
|
|
|
|
@-ms-viewport{width:device-width}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;line-height:0;content:""}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.hidden{display:none;visibility:hidden}.visible-phone{display:none!important}.visible-tablet{display:none!important}.hidden-desktop{display:none!important}.visible-desktop{display:inherit!important}@media(min-width:768px) and (max-width:979px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-tablet{display:inherit!important}.hidden-tablet{display:none!important}}@media(max-width:767px){.hidden-desktop{display:inherit!important}.visible-desktop{display:none!important}.visible-phone{display:inherit!important}.hidden-phone{display:none!important}}@media(min-width:1200px){.row{margin-left:-30px;*zoom:1}.row:before,.row:after{display:table;line-height:0;content:""}.row:after{clear:both}[class*="span"]{float:left;min-height:1px;margin-left:30px}.container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px}.span12{width:1170px}.span11{width:1070px}.span10{width:970px}.span9{width:870px}.span8{width:770px}.span7{width:670px}.span6{width:570px}.span5{width:470px}.span4{width:370px}.span3{width:270px}.span2{width:170px}.span1{width:70px}.offset12{margin-left:1230px}.offset11{margin-left:1130px}.offset10{margin-left:1030px}.offset9{margin-left:930px}.offset8{margin-left:830px}.offset7{margin-left:730px}.offset6{margin-left:630px}.offset5{margin-left:530px}.offset4{margin-left:430px}.offset3{margin-left:330px}.offset2{margin-left:230px}.offset1{margin-left:130px}.row-fluid{width:100%;*zoom:1}.row-fluid:before,.row-fluid:after{display:table;line-height:0;content:""}.row-fluid:after{clear:both}.row-fluid [class*="span"]{display:block;float:left;width:100%;min-height:30px;margin-left:2.564102564102564%;*margin-left:2.5109110747408616%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.row-fluid [class*="span"]:first-child{margin-left:0}.row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.564102564102564%}.row-fluid .span12{width:100%;*width:99.94680851063829%}.row-fluid .span11{width:91.45299145299145%;*width:91.39979996362975%}.row-fluid .span10{width:82.90598290598291%;*width:82.8527914166212%}.row-fluid .span9{width:74.35897435897436%;*width:74.30578286961266%}.row-fluid .span8{width:65.81196581196582%;*width:65.75877432260411%}.row-fluid .span7{width:57.26495726495726%;*width:57.21176577559556%}.row-fluid .span6{width:48.717948717948715%;*width:48.664757228587014%}.row-fluid .span5{width:40.17094017094017%;*width:40.11774868157847%}.row-fluid .span4{width:31.623931623931625%;*width:31.570740134569924%}.row-fluid .span3{width:23.076923076923077%;*width:23.023731587561375%}.row-fluid .span2{width:14.52991452991453%;*width:14.476723040552828%}.row-fluid .span1{width:5.982905982905983%;*width:5.929714493544281%}.row-fluid .offset12{margin-left:105.12820512820512%;*margin-left:105.02182214948171%}.row-fluid .offset12:first-child{margin-left:102.56410256410257%;*margin-left:102.45771958537915%}.row-fluid .offset11{margin-left:96.58119658119658%;*margin-left:96.47481360247316%}.row-fluid .offset11:first-child{margin-left:94.01709401709402%;*margin-left:93.91071103837061%}.row-fluid .offset10{margin-left:88.03418803418803%;*margin-left:87.92780505546462%}.row-fluid .offset10:first-child{margin-left:85.47008547008548%;*margin-left:85.36370249136206%}.row-fluid .offset9{margin-left:79.48717948717949%;*margin-left:79.38079650845607%}.row-fluid .offset9:first-child{margin-left:76.92307692307693%;*margin-left:76.81669394435352%}.row-fluid .offset8{margin-left:70.94017094017094%;*margin-left:70.83378796144753%}.row-fluid .offset8:first-child{margin-left:68.37606837606839%;*margin-left:68.26968539734497%}.row-fluid .offset7{marg
|
|
|
|
`
|
|
|
|
|
|
|
|
|