all repos — flounder @ a74256627667d2f0329e264adb88477110ef0f25

A small site builder for the Gemini protocol

Add simple file renaming
alex wennerberg alex@alexwennerberg.com
Wed, 18 Nov 2020 19:39:17 -0800
commit

a74256627667d2f0329e264adb88477110ef0f25

parent

32fd85e62324db1a34b5e78e1ef7b61cee31edde

3 files changed, 10 insertions(+), 0 deletions(-)

jump to
M http.gohttp.go

@@ -141,6 +141,11 @@ log.Println(err)

renderError(w, InternalServerErrorMsg, 500) return } + newName := filepath.Clean(r.Form.Get("rename")) + if newName != fileName { + newPath := path.Join(c.FilesDirectory, authUser, newName) + os.Rename(filePath, newPath) + } http.Redirect(w, r, "/my_site", 303) } }
M templates/edit_file.htmltemplates/edit_file.html

@@ -1,6 +1,8 @@

{{template "header" .}} <h2>Editing {{.FileName}}</h2> <form id="edit-form" action="/edit/{{.FileName}}" method="POST"> + <label for="rename">Rename:</label> + <input type="text" value="{{.FileName}}" id="rename" name="rename"> <textarea rows="20" name="file_text" id="editor">{{.FileText}}</textarea> <br> <input type="submit" value="Save file" class="button">
M utils.goutils.go

@@ -45,6 +45,9 @@ func checkIfValidFile(filename string, fileBytes []byte) error {

if len(filename) == 0 { return fmt.Errorf("Please enter a filename") } + if len(filename) > 256 { // arbitrarily chosen + return fmt.Errorf("Filename is too long") + } ext := strings.ToLower(path.Ext(filename)) found := false for _, mimetype := range c.OkExtensions {