From 93cce3bc872c72acb186d35e029d61c0d821aab0 Mon Sep 17 00:00:00 2001 From: James Mills Date: Fri, 9 Apr 2021 21:35:57 +1000 Subject: [PATCH] Fix paste handler and uuid collision (Fixes #9) --- server.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/server.go b/server.go index 3b3b1eb..c9ffa04 100644 --- a/server.go +++ b/server.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "html/template" - "io/ioutil" "log" "net/http" "net/url" @@ -23,7 +22,6 @@ import ( rice "github.com/GeertJohan/go.rice" "github.com/julienschmidt/httprouter" "github.com/patrickmn/go-cache" - "github.com/renstrom/shortuuid" "github.com/timewasted/go-accept-headers" ) @@ -117,20 +115,15 @@ func (s *Server) PasteHandler() httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { s.counters.Inc("n_paste") - body, err := ioutil.ReadAll(r.Body) - log.Printf("body: %v", body) - if err != nil { - http.Error(w, "Internal Error", http.StatusInternalServerError) - return - } + blob := r.FormValue("blob") - if len(body) == 0 { + if len(blob) == 0 { http.Error(w, "Bad Request", http.StatusBadRequest) return } - uuid := shortuuid.NewWithNamespace(s.config.fqdn) - s.store.Set(uuid, string(body), cache.DefaultExpiration) + uuid := RandomString(8) + s.store.Set(uuid, blob, cache.DefaultExpiration) u, err := url.Parse(fmt.Sprintf("./p/%s", uuid)) if err != nil {