summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-14 04:10:52 +0100
committerache <ache@ache.one>2019-02-14 04:10:52 +0100
commitfdbb4eeedf8793e24903990742e8a847200cacb3 (patch)
tree5b5a3aae0c2af98d884d89249239046e6744c3e8
parenttest PUT front-end (diff)
Grid CSS
-rw-r--r--dir.html108
-rw-r--r--server.go35
2 files changed, 132 insertions, 11 deletions
diff --git a/dir.html b/dir.html
index b570d3e..9c240eb 100644
--- a/dir.html
+++ b/dir.html
@@ -4,8 +4,110 @@
{{if .Name}}<title>{{ .Name }}</title>{{end}}
</head>
<body>
-<pre>{{range .ListEntries}}
-<a href="{{ .Name }}">{{ .Name }}</a> {{ .Size }}{{end}}
+<h1>Index of {{ .Name }}</h1><br>
+<section id="main">
+<pre>{{range .ListFiles}}
+ <a href="{{ .Name }}">{{ .Name }}</a>{{ .Size }}{{end}}
</pre>
- </body>
+</section>
+<section id="nav">
+ <h2>List of directories</h2>
+<pre>{{range .ListCols}}
+ <a href="{{ .Name }}">{{ .Name }}</a>{{end}}
+</pre>
+</section>
+<section id="dav">
+ <div class="uploadDiv">
+ <label for="fileinput">Select File</label>
+ <input id="fileinput" type="file">
+ </div>
+ <div class="mkdirDiv">
+ </div>
+</section>
+<div id="footer">Create with love 💟</div>
+<script language="javascript">
+const input = document.getElementById('fileinput');
+
+const upload = (file) => {
+ const l = window.location;
+
+ let uri = l.protocol + '//' + l.hostname;
+ if( l.port !== '80' ) {
+ uri += ':' + l.port
+ }
+ uri += l.pathname
+
+ console.log(uri)
+
+ if( uri[uri.length - 1] !== '/' ) {
+ uri += '/'
+ }
+
+ uri += file.name
+
+ console.log(uri)
+
+ fetch( encodeURI(uri) , {
+ method: 'PUT',
+ headers: {
+ "Content-Type": file.type
+ },
+ body: file // This is your file object
+ }).then(
+ response => {
+ console.log(response);
+ }
+ ).then(
+ success => {
+ console.log(success);
+ }
+ ).catch(
+ error => {
+ console.log(error);
+ }
+ );
+};
+
+const onSelectFile = () => {
+ let i = 0;
+ for( ; i < input.files.length ; i++) {
+ upload(input.files[i]);
+ }
+}
+
+input.addEventListener('change', onSelectFile, false);
+</script>
+<style>
+body {
+ display: grid;
+ grid-template-columns: calc(100% / 6) calc(100% / 3 + 100% / 6) calc(100%/3);
+ grid-template-areas: "h h h"
+ "nav main dav"
+ "nav f f";
+}
+
+h1 {
+ grid-area: h;
+ background-color: #8ca0ff;
+}
+#nav {
+ grid-area: nav;
+ background-color: #ffa0fc;
+}
+
+#main {
+ grid-area: main;
+ background-color: #00ff64;
+}
+#dav {
+ grid-area: dav;
+ background-color: #ff0f64;
+}
+
+#footer {
+ grid-area: f;
+ background-color: #fcffa0;
+}
+</style>
+</body>
</html>
diff --git a/server.go b/server.go
index 6274934..d072342 100644
--- a/server.go
+++ b/server.go
@@ -40,10 +40,11 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
type Entry struct {
Name string
- Size int
+ Size int64
}
var files []Entry
+ var cols []Entry
f, err := os.Open(filename)
if err != nil {
@@ -68,16 +69,24 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
}
}
+
+ cols = append(cols, Entry{".", 0})
+ if filename != "." {
+ cols = append(cols, Entry{"..", 0})
+ }
for _, file := range fileInfo {
- files = append(files, Entry{file.Name(), 0})
+ if file.IsDir() {
+ cols = append(cols, Entry{file.Name(), 0})
+ } else {
+ files = append(files, Entry{file.Name(), file.Size()})
+ }
}
-
-
type Collection struct {
Name string
- ListEntries []Entry
+ ListCols []Entry
+ ListFiles []Entry
}
- tmpl.Execute(w, Collection{ "Title" , files})
+ tmpl.Execute(w, Collection{ "Title" , cols, files})
case stat.Mode().IsRegular():
if !headOnly {
@@ -161,13 +170,23 @@ func handleCopy( w http.ResponseWriter, r *http.Request) {
}
func handleMove( w http.ResponseWriter, r *http.Request) {
filename := r.URL.Path[1:]
- oups := ""
+ dest := r.Header.Get("Destination")
+ overwrite := "T"
+
+ if r.Header.Get("Overwrite") != "" {
+ overwrite = r.Header.Get("Overwrite")
+ }
+
if filename == "" || filename == "." {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintln(w, "Cannot move root directory")
return
}
- fmt.Printf("Trying to move [%s] to [%s]\n", filename, oups)
+
+ if tmpDir, err := os.Stat( path.Dir( dest ) ) ; err == nil && tmpDir.IsDir() {
+
+ }
+ fmt.Printf("Trying to move [%s] to [%s]\n", filename, dest)
}
func handleMethod( w http.ResponseWriter, r *http.Request) {