v0.5: dependencies update, EOF fix for PUT/POST /v1/file

This commit is contained in:
default
2024-08-09 02:10:48 +08:00
parent 93359110a2
commit 73e481bc96
4 changed files with 31 additions and 44 deletions

View File

@@ -17,6 +17,7 @@ func NewHandler(cfg *config.Config) http.Handler {
mux.HandleFunc("GET /v1/list/{what}", wrap(cfg, v1.List))
mux.HandleFunc("GET /v1/file", v1.GetFileContent)
mux.HandleFunc("GET /v1/file/{filename}", v1.GetFileContent)
mux.HandleFunc("POST /v1/file/{filename}", v1.SetFileContent)
mux.HandleFunc("PUT /v1/file/{filename}", v1.SetFileContent)
mux.HandleFunc("GET /v1/stats", wrap(cfg, v1.Stats))
return mux

View File

@@ -1,6 +1,7 @@
package v1
import (
"io"
"net/http"
"os"
"path"
@@ -31,8 +32,7 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
U.HandleErr(w, r, U.ErrMissingKey("filename"), http.StatusBadRequest)
return
}
content := make([]byte, r.ContentLength)
_, err := E.Check(r.Body.Read(content))
content, err := E.Check(io.ReadAll(r.Body))
if err.IsNotNil() {
U.HandleErr(w, r, err)
return
@@ -45,7 +45,7 @@ func SetFileContent(w http.ResponseWriter, r *http.Request) {
}
if err.IsNotNil() {
U.HandleErr(w, r, err)
U.HandleErr(w, r, err, http.StatusBadRequest)
return
}