2013-02-09 05:11:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-03-27 20:30:24 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"text/template"
|
2013-08-06 00:29:16 +00:00
|
|
|
|
2017-04-07 18:55:13 +00:00
|
|
|
humanize "github.com/dustin/go-humanize"
|
2013-08-06 00:29:16 +00:00
|
|
|
"github.com/vbatts/imgsrv/types"
|
2013-02-09 05:11:52 +00:00
|
|
|
)
|
|
|
|
|
2013-02-11 19:27:38 +00:00
|
|
|
var emptyInterface interface{}
|
|
|
|
|
|
|
|
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-08-05 23:27:07 +00:00
|
|
|
|
|
|
|
<script src="/assets/jquery.js" type="text/javascript" ></script>
|
|
|
|
<script src="/assets/jqud.js" type="text/javascript" ></script>
|
|
|
|
<script src="/assets/bootstrap.js" type="text/javascript" ></script>
|
|
|
|
|
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>
|
2013-05-08 18:28:49 +00:00
|
|
|
<li><a href="/all">All</a></li>
|
2013-02-12 15:21:25 +00:00
|
|
|
</ul>
|
2013-08-06 03:51:26 +00:00
|
|
|
<div class="dropdown nav pull-right">
|
|
|
|
<a role="button" data-toggle="dropdown" href="#">Other<b class="caret"></b></a>
|
|
|
|
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
|
|
|
|
<li><a href="/k/">Keywords</a></li>
|
|
|
|
<li><a href="/ext/">File ext</a></li>
|
|
|
|
<li><a href="/md5/">MD5s</a></li>
|
|
|
|
</ul>
|
|
|
|
</div> <!-- dropdown -->
|
|
|
|
</div> <!-- nav-collapse -->
|
|
|
|
</div> <!-- container-fluid -->
|
|
|
|
</div> <!-- navbar-inner -->
|
|
|
|
</div> <!-- navbar top -->
|
|
|
|
<script>$('.dropdown-toggle').dropdown()</script>
|
2013-02-12 15:21:25 +00:00
|
|
|
|
|
|
|
`
|
|
|
|
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
|
|
|
|
2013-06-04 20:43:16 +00:00
|
|
|
var formDeleteFileTemplate = template.Must(template.New("formDeleteFile").Parse(formDeleteFileTemplateHTML))
|
|
|
|
var formDeleteFileTemplateHTML = `
|
|
|
|
<div class="span9">
|
|
|
|
<div class="hero-unit">
|
|
|
|
<h3>Get file from URL</h3>
|
|
|
|
{{if .}}
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<b>Are you sure?</b>
|
|
|
|
</tr>
|
|
|
|
<br/>
|
|
|
|
<tr>
|
|
|
|
<td>
|
2013-08-06 03:51:26 +00:00
|
|
|
<a role="button" href="/v/{{.}}">no!</a>
|
2013-06-04 20:43:16 +00:00
|
|
|
<br/>
|
2013-08-06 03:51:26 +00:00
|
|
|
<a role="button" href="/f/{{.}}?delete=true&confirm=true">yes! delete!</a>
|
2013-06-04 20:43:16 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
{{else}}
|
|
|
|
<p>
|
|
|
|
<b>ERROR: No File provided!</b>
|
|
|
|
</p>
|
|
|
|
{{end}}
|
|
|
|
</div>{{/* hero-unit */}}
|
|
|
|
</div>{{/* span9 */}}
|
|
|
|
`
|
|
|
|
|
2013-02-12 16:04:48 +00:00
|
|
|
var formGetUrlTemplate = template.Must(template.New("formGetUrl").Parse(formGetUrlTemplateHTML))
|
|
|
|
var formGetUrlTemplateHTML = `
|
|
|
|
<div class="span9">
|
|
|
|
<div class="hero-unit">
|
|
|
|
<h3>Get file from URL</h3>
|
|
|
|
<form enctype="multipart/form-data" action="/urlie" method="POST">
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<input type="text" name="url" placeholder="file URL"><br/>
|
2013-05-08 18:28:49 +00:00
|
|
|
<input type="text" name="keywords" placeholder="keywords"><i>(comma seperatated, no spaces)</i><br/>
|
|
|
|
<input type="checkbox" name="rand" value="true">Randomize filename
|
2013-02-12 16:04:48 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<input type="submit" value="Fetch File"><br/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</td>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
</div>{{/* hero-unit */}}
|
|
|
|
</div>{{/* span9 */}}
|
|
|
|
`
|
|
|
|
|
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">
|
2013-02-12 16:04:48 +00:00
|
|
|
<h3>Upload a File</h3>
|
2013-02-12 15:21:25 +00:00
|
|
|
<form enctype="multipart/form-data" action="/upload" method="POST">
|
|
|
|
<table>
|
|
|
|
<tr>
|
2013-02-12 15:27:59 +00:00
|
|
|
<td>
|
|
|
|
<input type="file" name="filename" placeholder="filename"><br/>
|
2013-05-08 18:28:49 +00:00
|
|
|
<input type="text" name="keywords" placeholder="keywords"><i>(comma seperatated, no spaces)</i><br/>
|
|
|
|
<input type="checkbox" name="rand" value="true">Randomize filename
|
2013-02-12 15:27:59 +00:00
|
|
|
</td>
|
2013-02-12 15:21:25 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2013-02-12 15:27:59 +00:00
|
|
|
<td>
|
2013-02-12 15:21:25 +00:00
|
|
|
<input type="submit" value="Upload File"><br/>
|
2013-02-12 15:27:59 +00:00
|
|
|
</td>
|
2013-02-12 15:21:25 +00:00
|
|
|
</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-05-09 13:36:21 +00:00
|
|
|
<li>
|
|
|
|
<a href="/v/{{.Filename}}">{{.Filename}}</a>
|
2013-02-12 15:21:25 +00:00
|
|
|
[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
|
|
|
`
|
2013-05-09 13:36:21 +00:00
|
|
|
|
2013-08-06 00:29:16 +00:00
|
|
|
var tagcloudTemplate = template.Must(template.New("tagcloud").Parse(tagcloudTemplateHTML))
|
|
|
|
var tagcloudTemplateHTML = `
|
|
|
|
{{if .}}
|
2013-08-06 14:37:58 +00:00
|
|
|
<div id="tagCloud">
|
2013-08-06 00:29:16 +00:00
|
|
|
{{range .}}
|
2013-09-10 18:51:44 +00:00
|
|
|
<a href="/{{.Root}}/{{.Id}}" rel="{{.Value}}">{{.Id}}</a>
|
2013-08-06 00:29:16 +00:00
|
|
|
{{end}}
|
|
|
|
</div>
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$.fn.tagcloud.defaults = {
|
|
|
|
size: {start: 9, end: 40, unit: 'pt'},
|
|
|
|
color: {start: '#007ab7', end: '#e55b00'}
|
|
|
|
};
|
|
|
|
|
|
|
|
$(function () {
|
2013-08-06 15:24:54 +00:00
|
|
|
$('#tagCloud a').tagcloud();
|
2013-08-06 00:29:16 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
`
|
|
|
|
|
2013-05-09 16:36:49 +00:00
|
|
|
var fileViewImageTemplate = template.Must(template.New("file").Parse(fileViewImageTemplateHTML))
|
|
|
|
var fileViewImageTemplateHTML = `
|
|
|
|
{{if .}}
|
|
|
|
<a href="/f/{{.Filename}}"><img src="/f/{{.Filename}}"></a>
|
|
|
|
{{end}}
|
|
|
|
`
|
|
|
|
|
2013-06-03 14:55:04 +00:00
|
|
|
var fileViewAudioTemplate = template.Must(template.New("file").Parse(fileViewAudioTemplateHTML))
|
|
|
|
var fileViewAudioTemplateHTML = `
|
|
|
|
{{if .}}
|
|
|
|
<a href="/f/{{.Filename}}">
|
|
|
|
<audio controls>
|
2017-08-08 20:24:05 +00:00
|
|
|
<source src="/f/{{.Filename}}" autoplay/>
|
2013-06-03 14:55:04 +00:00
|
|
|
Your browser does not support the video tag.
|
|
|
|
</audio>
|
|
|
|
</a>
|
|
|
|
{{end}}
|
|
|
|
`
|
|
|
|
|
2013-05-09 16:36:49 +00:00
|
|
|
var fileViewVideoTemplate = template.Must(template.New("file").Parse(fileViewVideoTemplateHTML))
|
|
|
|
var fileViewVideoTemplateHTML = `
|
|
|
|
{{if .}}
|
|
|
|
<a href="/f/{{.Filename}}">
|
|
|
|
<video width="320" height="240" controls>
|
2017-08-08 20:24:05 +00:00
|
|
|
<source src="/f/{{.Filename}}" autoplay/>
|
2013-05-09 16:36:49 +00:00
|
|
|
Your browser does not support the video tag.
|
|
|
|
</video>
|
|
|
|
</a>
|
|
|
|
{{end}}
|
|
|
|
`
|
|
|
|
|
2013-05-09 13:36:21 +00:00
|
|
|
var fileViewTemplate = template.Must(template.New("file").Parse(fileViewTemplateHTML))
|
|
|
|
var fileViewTemplateHTML = `
|
2013-05-08 18:28:49 +00:00
|
|
|
{{if .}}
|
2013-05-09 13:36:21 +00:00
|
|
|
<a href="/f/{{.Filename}}">{{.Filename}}</a>
|
|
|
|
{{end}}
|
2013-05-09 16:36:49 +00:00
|
|
|
`
|
|
|
|
|
2017-04-07 18:55:13 +00:00
|
|
|
var funcs = template.FuncMap{
|
|
|
|
"humanBytes": humanize.Bytes,
|
|
|
|
"humanTime": humanize.Time,
|
|
|
|
}
|
|
|
|
|
|
|
|
var fileViewInfoTemplate = template.Must(template.New("file").Funcs(funcs).Parse(fileViewInfoTemplateHTML))
|
2013-05-09 16:36:49 +00:00
|
|
|
var fileViewInfoTemplateHTML = `
|
|
|
|
{{if .}}
|
2013-05-08 18:28:49 +00:00
|
|
|
<br/>
|
|
|
|
[keywords:{{range $key := .Metadata.Keywords}} <a href="/k/{{$key}}">{{$key}}</a>{{end}}]
|
|
|
|
<br/>
|
2013-05-09 16:53:11 +00:00
|
|
|
[md5: <a href="/md5/{{.Md5}}">{{.Md5}}</a>]
|
|
|
|
<br/>
|
2017-04-07 18:55:13 +00:00
|
|
|
[size: {{humanBytes .Length}}]
|
2013-05-09 16:53:11 +00:00
|
|
|
<br/>
|
2017-04-07 18:55:13 +00:00
|
|
|
[UploadDate: {{.Metadata.TimeStamp}} ({{humanTime .Metadata.TimeStamp}})]
|
2013-06-04 20:43:16 +00:00
|
|
|
<br/>
|
|
|
|
[<a href="/f/{{.Filename}}?delete=true">Delete</a>]
|
2013-05-08 18:28:49 +00:00
|
|
|
{{end}}
|
|
|
|
`
|
2013-02-11 19:27:38 +00:00
|
|
|
|
2013-06-04 20:43:16 +00:00
|
|
|
func DeleteFilePage(w io.Writer, filename string) (err error) {
|
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: delete"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = formDeleteFileTemplate.Execute(w, &filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-02-12 16:04:48 +00:00
|
|
|
func UrliePage(w io.Writer) (err error) {
|
2013-03-27 20:30:24 +00:00
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: URLie"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = formGetUrlTemplate.Execute(w, &emptyInterface)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
2013-02-12 16:04:48 +00:00
|
|
|
}
|
2013-05-08 18:28:49 +00:00
|
|
|
|
2013-02-11 19:27:38 +00:00
|
|
|
func UploadPage(w io.Writer) (err error) {
|
2013-03-27 20:30:24 +00:00
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: Upload"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-05-08 18:28:49 +00:00
|
|
|
|
2013-05-09 16:13:46 +00:00
|
|
|
// main context of this page
|
2013-03-27 20:30:24 +00:00
|
|
|
err = formFileUploadTemplate.Execute(w, &emptyInterface)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-05-08 18:28:49 +00:00
|
|
|
|
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:13:46 +00:00
|
|
|
func ImageViewPage(w io.Writer, file types.File) (err error) {
|
2013-05-08 18:28:49 +00:00
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2013-05-09 16:36:49 +00:00
|
|
|
if file.IsImage() {
|
|
|
|
err = fileViewImageTemplate.Execute(w, file)
|
2013-06-03 14:55:04 +00:00
|
|
|
} else if file.IsAudio() {
|
|
|
|
err = fileViewAudioTemplate.Execute(w, file)
|
2013-05-09 16:36:49 +00:00
|
|
|
} else if file.IsVideo() {
|
|
|
|
err = fileViewVideoTemplate.Execute(w, file)
|
|
|
|
} else {
|
|
|
|
err = fileViewTemplate.Execute(w, file)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = fileViewInfoTemplate.Execute(w, file)
|
2013-05-08 18:28:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2013-03-27 20:30:24 +00:00
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
2013-02-11 19:27:38 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 16:13:46 +00:00
|
|
|
func ListFilesPage(w io.Writer, files []types.File) (err error) {
|
2013-03-27 20:30:24 +00:00
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-05-08 18:28:49 +00:00
|
|
|
|
2013-05-09 16:13:46 +00:00
|
|
|
// main context of this page
|
2013-03-27 20:30:24 +00:00
|
|
|
err = listTemplate.Execute(w, files)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-05-08 18:28:49 +00:00
|
|
|
|
2013-03-27 20:30:24 +00:00
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
2013-02-09 05:11:52 +00:00
|
|
|
}
|
2013-08-06 00:29:16 +00:00
|
|
|
|
2013-08-06 14:37:58 +00:00
|
|
|
func ListTagCloudPage(w io.Writer, ic []types.IdCount) (err error) {
|
2013-08-06 00:29:16 +00:00
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// main context of this page
|
2013-08-06 14:37:58 +00:00
|
|
|
err = tagcloudTemplate.Execute(w, ic)
|
2013-08-06 00:29:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2013-09-10 18:51:44 +00:00
|
|
|
|
|
|
|
func ErrorPage(w io.Writer, e error) (err error) {
|
|
|
|
err = headTemplate.Execute(w, map[string]string{"title": "FileSrv :: ERROR"})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = navbarTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = containerBeginTemplate.Execute(w, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// main context of this page
|
|
|
|
err = template.Must(template.New("serverError").Parse(`
|
|
|
|
{{if .}}
|
|
|
|
<div class="span9">
|
|
|
|
<div class="hero-unit">
|
|
|
|
<h3>ERROR!</h3>
|
|
|
|
<div class="error">
|
|
|
|
{{.Error()}}
|
|
|
|
</div>
|
|
|
|
</div> {{/* hero-unit */}}
|
|
|
|
</div> {{/* span9 */}}
|
|
|
|
{{end}}
|
|
|
|
`)).Execute(w, e)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = tailTemplate.Execute(w, map[string]string{"footer": fmt.Sprintf("Version: %s", VERSION)})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|