Fix paste handler and uuid collision (Fixes #9)
This commit is contained in:
parent
10645aa3a5
commit
93cce3bc87
15
server.go
15
server.go
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -23,7 +22,6 @@ import (
|
|||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
"github.com/renstrom/shortuuid"
|
|
||||||
"github.com/timewasted/go-accept-headers"
|
"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) {
|
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||||
s.counters.Inc("n_paste")
|
s.counters.Inc("n_paste")
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
blob := r.FormValue("blob")
|
||||||
log.Printf("body: %v", body)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, "Internal Error", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(body) == 0 {
|
if len(blob) == 0 {
|
||||||
http.Error(w, "Bad Request", http.StatusBadRequest)
|
http.Error(w, "Bad Request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid := shortuuid.NewWithNamespace(s.config.fqdn)
|
uuid := RandomString(8)
|
||||||
s.store.Set(uuid, string(body), cache.DefaultExpiration)
|
s.store.Set(uuid, blob, cache.DefaultExpiration)
|
||||||
|
|
||||||
u, err := url.Parse(fmt.Sprintf("./p/%s", uuid))
|
u, err := url.Parse(fmt.Sprintf("./p/%s", uuid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user