|
@@ -20,18 +20,12 @@ func Wildcard(w http.ResponseWriter, r *http.Request) {
|
|
|
if r.Method == "GET" {
|
|
if r.Method == "GET" {
|
|
|
base_dir := "./templates/"
|
|
base_dir := "./templates/"
|
|
|
endpoint := strings.TrimPrefix(r.URL.Path, "/")
|
|
endpoint := strings.TrimPrefix(r.URL.Path, "/")
|
|
|
- fmt.Println(endpoint)
|
|
|
|
|
- /*if endpoint == "" {
|
|
|
|
|
|
|
+ //fmt.Println(endpoint)
|
|
|
|
|
+ //fmt.Println(r.URL.Path)
|
|
|
|
|
+ if endpoint == "" {
|
|
|
//in cazul in care apelam root
|
|
//in cazul in care apelam root
|
|
|
- endpoint = "index"
|
|
|
|
|
|
|
+ endpoint = "index.html"
|
|
|
}
|
|
}
|
|
|
- path := filepath.Join("templates", endpoint+".tmpl")
|
|
|
|
|
- _, err := os.Stat(path)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
- w.Write(inout.FileToBytes("templates/error.tmpl"))
|
|
|
|
|
- return
|
|
|
|
|
- }*/
|
|
|
|
|
path := filepath.Join(base_dir, endpoint)
|
|
path := filepath.Join(base_dir, endpoint)
|
|
|
_, err := os.Stat(path)
|
|
_, err := os.Stat(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -44,7 +38,7 @@ func Wildcard(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func API(w http.ResponseWriter, r *http.Request, notesFolder string) {
|
|
|
|
|
|
|
+func API(w http.ResponseWriter, r *http.Request) {
|
|
|
action := strings.TrimPrefix(r.URL.Path, "/api/")
|
|
action := strings.TrimPrefix(r.URL.Path, "/api/")
|
|
|
if r.Method == "POST" {
|
|
if r.Method == "POST" {
|
|
|
//w.WriteHeader(http.StatusNotImplemented)
|
|
//w.WriteHeader(http.StatusNotImplemented)
|
|
@@ -52,19 +46,27 @@ func API(w http.ResponseWriter, r *http.Request, notesFolder string) {
|
|
|
switch action {
|
|
switch action {
|
|
|
case "save_note":
|
|
case "save_note":
|
|
|
r.ParseForm()
|
|
r.ParseForm()
|
|
|
- fisier := fmt.Sprintf("notita-%s.json", time.Now().Format("2006-01-02-150405.999999"))
|
|
|
|
|
- //fmt.Println(fisier, r.Form)
|
|
|
|
|
- //return
|
|
|
|
|
n := types.Notita{}
|
|
n := types.Notita{}
|
|
|
n.Titlu = r.Form.Get("titlu")
|
|
n.Titlu = r.Form.Get("titlu")
|
|
|
n.Continut = r.Form.Get("notita")
|
|
n.Continut = r.Form.Get("notita")
|
|
|
- err := inout.ObjToFile(filepath.Join(notesFolder, fisier), n, true)
|
|
|
|
|
|
|
+ n.Folder = r.Form.Get("director")
|
|
|
|
|
+ err := os.MkdirAll(n.Folder, 0755)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
+ fmt.Fprintf(w, "ParseForm error: %+v", err)
|
|
|
|
|
+ }
|
|
|
|
|
+ fisier := fmt.Sprintf("notita-%s.json", time.Now().Format("2006-01-02-150405.999999"))
|
|
|
|
|
+ //fmt.Println(fisier, r.Form)
|
|
|
|
|
+ //return
|
|
|
|
|
+
|
|
|
|
|
+ err = inout.ObjToFile(filepath.Join(n.Folder, fisier), n, true)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
fmt.Fprintf(w, "%+v", err)
|
|
fmt.Fprintf(w, "%+v", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
referinta := r.Referer()
|
|
referinta := r.Referer()
|
|
|
|
|
+ fmt.Println(referinta)
|
|
|
if referinta != "" {
|
|
if referinta != "" {
|
|
|
http.Redirect(w, r, referinta, http.StatusSeeOther)
|
|
http.Redirect(w, r, referinta, http.StatusSeeOther)
|
|
|
} else {
|
|
} else {
|