all repos — flounder @ 7068552cb491131c4b58a79149ac457333881ac5

A small site builder for the Gemini protocol

add delete file
alex wennerberg alex@alexwennerberg.com
Sat, 24 Oct 2020 10:30:52 -0700
commit

7068552cb491131c4b58a79149ac457333881ac5

parent

6888b8e79940eb9e79dc8edc4b55998e94d46911

2 files changed, 15 insertions(+), 1 deletions(-)

jump to
M http.gohttp.go

@@ -89,13 +89,23 @@ } else if r.Method == "POST" {

// 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) } }
M main.gomain.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 {