Base project to template
This commit is contained in:
24
server/.notes/create.go
Executable file
24
server/.notes/create.go
Executable file
@@ -0,0 +1,24 @@
|
||||
package notes
|
||||
|
||||
import (
|
||||
"html"
|
||||
"local/notes-server/filetree"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (n *Notes) Create(w http.ResponseWriter, r *http.Request) {
|
||||
content := r.FormValue("base")
|
||||
content = html.UnescapeString(content)
|
||||
content = strings.ReplaceAll(content, "\r", "")
|
||||
urlPath := path.Join(r.URL.Path, content)
|
||||
p := filetree.NewPathFromURL(urlPath)
|
||||
if p.IsDir() {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
url := *r.URL
|
||||
url.Path = path.Join("/edit/", p.BaseHREF)
|
||||
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
||||
}
|
||||
Reference in New Issue
Block a user