Add comments per heading
This commit is contained in:
37
server/comment.go
Executable file
37
server/comment.go
Executable file
@@ -0,0 +1,37 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"html"
|
||||
"local/notes-server/filetree"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *Server) comment(w http.ResponseWriter, r *http.Request) {
|
||||
log.Println("COMMAND", r.Method, r.FormValue("lineno"), r.FormValue("content"))
|
||||
if r.Method != "POST" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
linenos := r.FormValue("lineno")
|
||||
lineno, err := strconv.Atoi(linenos)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
comment := r.FormValue("content")
|
||||
comment = html.UnescapeString(comment)
|
||||
comment = strings.ReplaceAll(comment, "\r", "")
|
||||
|
||||
err = s.Notes.Comment(r.URL.Path, lineno, comment)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
url := *r.URL
|
||||
url.Path = path.Join("/notes/", filetree.NewPathFromURL(r.URL.Path).BaseHREF)
|
||||
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
||||
}
|
||||
@@ -33,6 +33,9 @@ func (s *Server) Routes() error {
|
||||
fmt.Sprintf("create/%s%s", wildcard, wildcard): {
|
||||
handler: s.gzip(s.authenticate(s.create)),
|
||||
},
|
||||
fmt.Sprintf("comment/%s%s", wildcard, wildcard): {
|
||||
handler: s.gzip(s.authenticate(s.comment)),
|
||||
},
|
||||
fmt.Sprintf("search"): {
|
||||
handler: s.gzip(s.authenticate(s.search)),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user