permissions changes
parent
738df48ad4
commit
7f25341906
|
|
@ -0,0 +1,43 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) edit(w http.ResponseWriter, r *http.Request) {
|
||||||
|
p := NewPathFromURL(r.URL.Path)
|
||||||
|
if p.IsDir() {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
head(w, r)
|
||||||
|
editHead(w, p)
|
||||||
|
editFile(w, p)
|
||||||
|
foot(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func editHead(w http.ResponseWriter, p Path) {
|
||||||
|
fmt.Fprintln(w, h2(p.MultiLink()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func editFile(w http.ResponseWriter, p Path) {
|
||||||
|
href := p.HREF
|
||||||
|
href = strings.TrimPrefix(href, "/")
|
||||||
|
hrefs := strings.SplitN(href, "/", 2)
|
||||||
|
href = hrefs[0]
|
||||||
|
if len(hrefs) > 1 {
|
||||||
|
href = hrefs[1]
|
||||||
|
}
|
||||||
|
b, _ := ioutil.ReadFile(p.Local)
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<form action="/submit/%s" method="post" style="width:100%%; height: 90%%">
|
||||||
|
<table style="width:100%%; height: 90%%">
|
||||||
|
<textarea name="content" style="width:100%%; min-height:90%%">%s</textarea>
|
||||||
|
</table>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
`, href, b)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package server
|
||||||
|
|
@ -16,6 +16,10 @@ func (s *Server) Routes() error {
|
||||||
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
|
||||||
handler: s.notes,
|
handler: s.notes,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
|
||||||
|
handler: s.edit,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,34 @@ func TestServerNotes(t *testing.T) {
|
||||||
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
|
|
||||||
w.Body.Reset()
|
w.Body.Reset()
|
||||||
r.URL.Path = "/serve/"
|
r.URL.Path = "/notes/"
|
||||||
s.notes(w, r)
|
s.notes(w, r)
|
||||||
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
|
|
||||||
w.Body.Reset()
|
w.Body.Reset()
|
||||||
r.URL.Path = "/serve/test"
|
r.URL.Path = "/notes/test"
|
||||||
s.notes(w, r)
|
s.notes(w, r)
|
||||||
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServerNotes(t *testing.T) {
|
||||||
|
s := New()
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
r := &http.Request{
|
||||||
|
URL: &url.URL{
|
||||||
|
Path: "/",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s.edit(w, r)
|
||||||
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
|
|
||||||
|
w.Body.Reset()
|
||||||
|
r.URL.Path = "/edit/"
|
||||||
|
s.edit(w, r)
|
||||||
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
|
|
||||||
|
w.Body.Reset()
|
||||||
|
r.URL.Path = "/edit/test"
|
||||||
|
s.edit(w, r)
|
||||||
|
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<header>
|
<header>
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css">
|
||||||
</header>
|
</header>
|
||||||
<body>
|
<body height="100%">
|
||||||
{{{}}}
|
{{{}}}
|
||||||
</body>
|
</body>
|
||||||
<footer>
|
<footer>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue