permissions changes

master
bel 2019-10-20 00:13:42 +00:00
parent 738df48ad4
commit 7f25341906
24 changed files with 73 additions and 3 deletions

0
TODO Normal file → Executable file
View File

0
config/config.go Normal file → Executable file
View File

0
main.go Normal file → Executable file
View File

0
server/dir.go Normal file → Executable file
View File

0
server/dir_test.go Normal file → Executable file
View File

0
server/dirs.go Normal file → Executable file
View File

0
server/dirs_test.go Normal file → Executable file
View File

43
server/edit.go Executable file
View File

@ -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)
}

1
server/edit_test.go Executable file
View File

@ -0,0 +1 @@
package server

0
server/file.go Normal file → Executable file
View File

0
server/file_test.go Normal file → Executable file
View File

0
server/files.go Normal file → Executable file
View File

0
server/files_test.go Normal file → Executable file
View File

0
server/notes.go Normal file → Executable file
View File

0
server/notes_test.go Normal file → Executable file
View File

0
server/path.go Normal file → Executable file
View File

0
server/path_test.go Normal file → Executable file
View File

0
server/paths.go Normal file → Executable file
View File

0
server/paths_test.go Normal file → Executable file
View File

4
server/routes.go Normal file → Executable file
View File

@ -16,6 +16,10 @@ func (s *Server) Routes() error {
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
handler: s.notes,
},
{
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
handler: s.edit,
},
}
for _, endpoint := range endpoints {

26
server/routes_test.go Normal file → Executable file
View File

@ -27,12 +27,34 @@ func TestServerNotes(t *testing.T) {
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/serve/"
r.URL.Path = "/notes/"
s.notes(w, r)
t.Logf("serve %s: %s", r.URL.Path, w.Body.Bytes())
w.Body.Reset()
r.URL.Path = "/serve/test"
r.URL.Path = "/notes/test"
s.notes(w, r)
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())
}

0
server/server.go Normal file → Executable file
View File

0
server/server_test.go Normal file → Executable file
View File

2
wrapper.html Normal file → Executable file
View File

@ -2,7 +2,7 @@
<header>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css">
</header>
<body>
<body height="100%">
{{{}}}
</body>
<footer>