Initial commit
This commit is contained in:
95
fstore/pages/page.go
Normal file
95
fstore/pages/page.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
Path string
|
||||
Dirs []string
|
||||
Files []string
|
||||
|
||||
// Created in Render.
|
||||
BreadCrumbs []Directory
|
||||
}
|
||||
|
||||
func (ctx Page) FullPath(dir string) string {
|
||||
return filepath.Join(ctx.Path, dir)
|
||||
}
|
||||
|
||||
func (ctx Page) Render(w io.Writer) {
|
||||
crumbs := []Directory{}
|
||||
current := Directory(ctx.Path)
|
||||
|
||||
for current != "/" {
|
||||
crumbs = append([]Directory{current}, crumbs...)
|
||||
current = Directory(filepath.Dir(string(current)))
|
||||
}
|
||||
|
||||
ctx.BreadCrumbs = crumbs
|
||||
authRegisterTmpl.Execute(w, ctx)
|
||||
}
|
||||
|
||||
var authRegisterTmpl = template.Must(template.New("").Parse(`
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="/static/css/pure-min.css">
|
||||
<style>
|
||||
body {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
input[type=file] {
|
||||
padding: 0.4em .6em;
|
||||
display: inline-block;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: inset 0 1px 3px #ddd;
|
||||
border-radius: 4px;
|
||||
vertical-align: middle;
|
||||
box-sizing: border-box;
|
||||
width: 350px;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
<a href="/">root</a> / {{range .BreadCrumbs}}<a href="{{.}}">{{.Name}}</a> / {{end -}}
|
||||
</h1>
|
||||
|
||||
<form class="pure-form" method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend>Upload a file</legend>
|
||||
<input type="hidden" name="Action" value="Upload">
|
||||
<input id="File" name="File" type="file">
|
||||
<input type="text" id="Path" name="Path" placeholder="Relative path (optional)" />
|
||||
<button type="submit" class="pure-button pure-button-primary">Upload</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<a href="../">../</a><br>
|
||||
{{range .Dirs}}
|
||||
<a href="{{$.FullPath .}}">{{.}}/</a><br>
|
||||
{{end}}
|
||||
|
||||
{{range .Files}}
|
||||
<form style="display:inline-block; margin:0;" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="Action" value="Delete">
|
||||
<input type="hidden" id="Path" name="Path" value="{{$.FullPath .}}">
|
||||
[<a href="#" onclick="this.closest('form').submit();return false;">X</a>]
|
||||
</form>
|
||||
<a href="{{$.FullPath .}}">{{.}}</a>
|
||||
<br>
|
||||
{{end}}
|
||||
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
|
||||
type Directory string
|
||||
|
||||
func (d Directory) Name() string {
|
||||
return filepath.Base(string(d))
|
||||
}
|
||||
Reference in New Issue
Block a user