parent
f53fc80f68
commit
f582410c40
|
|
@ -1,15 +1,11 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"local/notes-server/filetree"
|
"local/notes-server/filetree"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (n *Notes) Delete(urlPath string) error {
|
func (n *Notes) Delete(urlPath string) error {
|
||||||
p := filetree.NewPathFromURL(urlPath)
|
p := filetree.NewPathFromURL(urlPath)
|
||||||
if p.IsDir() {
|
|
||||||
return errors.New("path is dir")
|
|
||||||
}
|
|
||||||
return os.Remove(p.Local)
|
return os.Remove(p.Local)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,27 @@ func TestDelete(t *testing.T) {
|
||||||
if _, err := os.Stat("/tmp/a"); err == nil {
|
if _, err := os.Stat("/tmp/a"); err == nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d, err := ioutil.TempDir(os.TempDir(), "trydel*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
f, err := ioutil.TempFile(d, "file*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
if err := n.Delete(d); err == nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
e, err := ioutil.TempDir(os.TempDir(), "trydel*")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := n.Delete(e); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
hi
|
# Hello
|
||||||
|
|
||||||
|
## World
|
||||||
|
|
@ -23,12 +23,7 @@ func (s *Server) notes(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func notesHead(w http.ResponseWriter, p filetree.Path) {
|
func notesHead(w http.ResponseWriter, p filetree.Path) {
|
||||||
fmt.Fprintln(w, h2(p.MultiLink(), "margin: 0; position: fixed; padding: .25em; background-color: #202b38; width: 100%; top: 0;"))
|
fmt.Fprintln(w, h2(p.MultiLink(), "margin: 0; position: fixed; padding: .25em; background-color: #202b38; width: 100%; top: 0;"))
|
||||||
fmt.Fprintf(w, `
|
htmlSearch(w)
|
||||||
<form action=%q method="post" style="padding-top: 2.5em">
|
|
||||||
<input type="text" name="keywords"></input>
|
|
||||||
<button type="submit">Search</button>
|
|
||||||
</form>
|
|
||||||
`, "/search")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) dir(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) dir(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -43,12 +38,8 @@ func (s *Server) dir(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dirHead(w http.ResponseWriter, baseHREF string) {
|
func dirHead(w http.ResponseWriter, baseHREF string) {
|
||||||
fmt.Fprintf(w, `
|
htmlCreate(w, baseHREF)
|
||||||
<form action=%q method="get">
|
htmlDelete(w, baseHREF)
|
||||||
<input type="text" name="base"></input>
|
|
||||||
<button type="submit">Create</button>
|
|
||||||
</form>
|
|
||||||
`, path.Join("/create/", baseHREF))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) file(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) file(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -62,10 +53,36 @@ func (s *Server) file(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileHead(w http.ResponseWriter, baseHREF string) {
|
func fileHead(w http.ResponseWriter, baseHREF string) {
|
||||||
fmt.Fprintf(w, `
|
htmlEdit(w, baseHREF)
|
||||||
<a href=%q><input type="button" value="Edit"></input></a>
|
htmlDelete(w, baseHREF)
|
||||||
`, path.Join("/edit/", baseHREF))
|
}
|
||||||
fmt.Fprintf(w, `
|
|
||||||
<a href=%q><input type="button" value="Delete" onclick="return confirm('Delete?');"></input></a>
|
func htmlEdit(w http.ResponseWriter, baseHREF string) {
|
||||||
`, path.Join("/delete/", baseHREF))
|
fmt.Fprintf(w, `<div style='display:inline-block'>
|
||||||
|
<a href=%q><input type="button" value="Edit"></input></a>
|
||||||
|
</div><br>`, path.Join("/edit/", baseHREF))
|
||||||
|
}
|
||||||
|
|
||||||
|
func htmlDelete(w http.ResponseWriter, baseHREF string) {
|
||||||
|
fmt.Fprintf(w, `<div style='display:inline-block'>
|
||||||
|
<a href=%q><input type="button" value="Delete" onclick="return confirm('Delete?');"></input></a>
|
||||||
|
</div><br>`, path.Join("/delete/", baseHREF))
|
||||||
|
}
|
||||||
|
|
||||||
|
func htmlCreate(w http.ResponseWriter, baseHREF string) {
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<form action=%q method="get">
|
||||||
|
<input type="text" name="base"></input>
|
||||||
|
<button type="submit">Create</button>
|
||||||
|
</form>
|
||||||
|
`, path.Join("/create/", baseHREF))
|
||||||
|
}
|
||||||
|
|
||||||
|
func htmlSearch(w http.ResponseWriter) {
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<form action=%q method="post" style="padding-top: 2.5em">
|
||||||
|
<input type="text" name="keywords"></input>
|
||||||
|
<button type="submit">Search</button>
|
||||||
|
</form>
|
||||||
|
`, "/search")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue