|
@@ -132,28 +132,60 @@ func safeDirectory(path string) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ListNotes(w http.ResponseWriter, r *http.Request) {
|
|
func ListNotes(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
+
|
|
|
if r.Method == "GET" {
|
|
if r.Method == "GET" {
|
|
|
- w.Write(inout.FileToBytes("./templates/list_notes.tmpl"))
|
|
|
|
|
- buildFolderStructure("./notes_folder", w)
|
|
|
|
|
|
|
+ f := types.Folder{}
|
|
|
|
|
+ err := buildFolderStructure("./notes_folder", &f)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("EROARE la buildFolderStructure:", err)
|
|
|
|
|
+ w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
+ fmt.Fprintf(w, "%+v", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ tmpl := template.New("list_notes_test")
|
|
|
|
|
+ _, err = tmpl.ParseFiles("./templates/list_notes.tmpl")
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("EROARE la buildFolderStructure:", err)
|
|
|
|
|
+ w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
+ fmt.Fprintf(w, "%+v", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ err = tmpl.ExecuteTemplate(w, "list_notes.tmpl", f)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("EROARE la buildFolderStructure:", err)
|
|
|
|
|
+ w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
+ fmt.Fprintf(w, "%+v", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+ w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
|
+ w.Write([]byte("methoda nepermisa"))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func buildFolderStructure(path string, w http.ResponseWriter /*f []types.Folder*/) {
|
|
|
|
|
|
|
+func buildFolderStructure(path string, f *types.Folder) error {
|
|
|
entries, err := os.ReadDir(path)
|
|
entries, err := os.ReadDir(path)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- w.WriteHeader(http.StatusBadRequest)
|
|
|
|
|
- fmt.Fprintf(w, "%+v", err)
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
|
|
+ f.Nume = filepath.Clean(path)
|
|
|
|
|
+
|
|
|
for _, entry := range entries {
|
|
for _, entry := range entries {
|
|
|
- /*if entry.IsDir() {
|
|
|
|
|
- w.WriteHeader(http.StatusNotImplemented)
|
|
|
|
|
- fmt.Fprint(w, "Functie Neimplementata - Subdirectorii")
|
|
|
|
|
- }*/
|
|
|
|
|
- fmt.Fprintln(w, entry, entry.IsDir())
|
|
|
|
|
|
|
+
|
|
|
if entry.IsDir() {
|
|
if entry.IsDir() {
|
|
|
- buildFolderStructure(filepath.Join(path, entry.Name()), w)
|
|
|
|
|
|
|
+ sub := types.Folder{}
|
|
|
|
|
+ err = buildFolderStructure(filepath.Join(path, entry.Name()), &sub)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ f.Subfoldere = append(f.Subfoldere, sub)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fisier := types.Fisier{
|
|
|
|
|
+ Nume: entry.Name(),
|
|
|
|
|
+ Path: filepath.Join(path, entry.Name()),
|
|
|
|
|
+ }
|
|
|
|
|
+ f.Fisiere = append(f.Fisiere, fisier)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|