flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 7068552cb491131c4b58a79149ac457333881ac5
parent 6888b8e79940eb9e79dc8edc4b55998e94d46911
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat, 24 Oct 2020 10:30:52 -0700

add delete file

Diffstat:
Mhttp.go | 12+++++++++++-
Mmain.go | 4++++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/http.go b/http.go @@ -89,13 +89,23 @@ func editFileHandler(w http.ResponseWriter, r *http.Request) { // get post body r.ParseForm() fileText := r.Form.Get("file_text") - ioutil.WriteFile(filePath, []byte(fileText), 0644) + err := ioutil.WriteFile(filePath, []byte(fileText), 0644) + if err != nil { + log.Println(err) + renderError(w, InternalServerErrorMsg, 500) + return + } http.Redirect(w, r, "/my_site", 302) } } func deleteFileHandler(w http.ResponseWriter, r *http.Request) { + authUser := "alex" + fileName := filepath.Clean(r.URL.Path[len("/delete/"):]) + filePath := path.Join(c.FilesDirectory, authUser, fileName) if r.Method == "POST" { + os.Remove(filePath) + http.Redirect(w, r, "/my_site", 302) } } diff --git a/main.go b/main.go @@ -26,6 +26,10 @@ func getUsers() ([]string, error) { return []string{"me", "other guy"}, nil } +/// Perform some checks to make sure the file is OK +func checkIfValidFile() { +} + func getIndexFiles() ([]*File, error) { // cache this function result := []*File{} err := filepath.Walk(userFilesPath, func(path string, info os.FileInfo, err error) error {