summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.json1
-rw-r--r--main.go5
-rw-r--r--root.template4
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 @@
<label for="doupload">Vis upload</label>
<input type="checkbox" id="doupload">
<div id="upload-box">
- <form method="POST" action="/upload" enctype="multipart/form-data">
+ <form method="POST" action="{{ .Root }}/upload" enctype="multipart/form-data">
<input type="input" name="h">
<input type="file" name="f" accept="image/*,.pdf,.txt,.md" capture>
<input type="submit" value="go">
@@ -124,7 +124,7 @@
<td>{{ .Name }}</td>
{{ $files := index $.Files .Hash }}
<td>{{ range $i, $f := $files }}
- <a href="/data/{{$f}}">[{{ $i }}] </a>
+ <a href="{{ $.Root }}/data/{{$f}}">[{{ $i }}] </a>
{{ end }}</td>
</tr>
{{ end }}