Skip to content

Commit

Permalink
impr: Allow Content header for writing a file
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT2 committed Jul 7, 2024
1 parent bf4b238 commit eb0c3fe
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,31 @@ func HandlePostRequest(ctx *fasthttp.RequestCtx, path string) {
return
}

// If the content key was provided, write to said file
content := ctx.FormValue("content")
if len(content) > 0 {
err = WriteToFile(path, strings.ReplaceAll(string(content), "\\n", "\n"))
writeFile := func(content []byte) (success bool) {
if len(content) > 0 {
err = WriteToFile(path, strings.ReplaceAll(string(content), "\\n", "\n"))

if err != nil {
HandleInternalServerError(ctx, err)
return
if err != nil {
HandleInternalServerError(ctx, err)
return
}

PrintResponsePath(ctx, path, false)
return true
}

PrintResponsePath(ctx, path, false)
return
}

// If the content key was provided, write to said file
content := ctx.FormValue("content")
if writeFile(content) {
return
}

// If the content header was provided, write to said file
contentHeader := ctx.Request.Header.Peek("Content")
if writeFile(contentHeader) {
return
}

Expand Down

0 comments on commit eb0c3fe

Please sign in to comment.