36 lines
834 B
Go
Executable File
36 lines
834 B
Go
Executable File
package server
|
|
|
|
import (
|
|
"html"
|
|
"gitea.inhome.blapointe.com/local/notes-server/filetree"
|
|
"net/http"
|
|
"path"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func (s *Server) comment(w http.ResponseWriter, r *http.Request) {
|
|
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)
|
|
}
|