From 5af37b83f0204bb43218547defbf7c6c817986a6 Mon Sep 17 00:00:00 2001 From: Julian T Date: Thu, 10 Sep 2020 23:20:25 +0200 Subject: Root can be set in config --- config.json | 1 + main.go | 5 ++++- root.template | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config.json b/config.json index 0bf434a..ee541c2 100644 --- a/config.json +++ b/config.json @@ -2,6 +2,7 @@ "listen": "localhost:8080", "db": "user=julian dbname=noteman sslmode=disable", "tmpl": "", + "root": "", "data": "data", "max_upload": 10, diff --git a/main.go b/main.go index 0ebbdc4..12389af 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ type Config struct { Listen string `json:"listen"` DBStr string `json:"db"` TmplPath string `json:"tmpl"` + Root string `json:"root"` DataPath string `json:"data"` MaxSize uint `json:"max_upload"` @@ -210,8 +211,10 @@ func (s *Server) httpRoot(w http.ResponseWriter, r *http.Request) { Notes []note Msg string Files *map[string][]string + Root string } page.Files = &s.filestore + page.Root = s.conf.Root err := s.db.SelectContext(r.Context(), &page.Notes, ` SELECT hash, name, location FROM notes WHERE available = True`) @@ -280,7 +283,7 @@ func (s *Server) httpUpload(w http.ResponseWriter, r *http.Request) { s.saveFile(hash, fname) s.httpLog(r, "Uploaded file %s", fname) - http.Redirect(w, r, "/", http.StatusSeeOther) + http.Redirect(w, r, s.conf.Root + "/", http.StatusSeeOther) } func (s *Server) allocFile(hash string, t string) (string, error) { diff --git a/root.template b/root.template index 74fbc0c..616d0b2 100644 --- a/root.template +++ b/root.template @@ -46,7 +46,7 @@
-
+ @@ -124,7 +124,7 @@ {{ .Name }} {{ $files := index $.Files .Hash }} {{ range $i, $f := $files }} - [{{ $i }}] + [{{ $i }}] {{ end }} {{ end }} -- cgit v1.2.3