From 05e438eb231bd16917655364e417d5920cbf1ecf Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Tue, 17 May 2022 01:10:36 +0200 Subject: [PATCH] changed delete share url --- internal/web/web.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/internal/web/web.go b/internal/web/web.go index 6e448a7..76d6c49 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -17,10 +17,6 @@ type createShare struct { Key string `json:"key"` } -type deleteShare struct { - Slug string `json:"slug"` -} - func StartWebserver(addr string, client client.Client, username, password string) error { if username == "" || password == "" { return errors.New("API username and password must be set") @@ -100,20 +96,14 @@ func StartWebserver(addr string, client client.Client, username, password string json.NewEncoder(w).Encode(share) }).Methods("POST") - r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) { + r.HandleFunc("/api/share/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) { if !checkAuth(w, r, username, password) { return } - var shareParams deleteShare - err := json.NewDecoder(r.Body).Decode(&shareParams) - if err != nil { - logrus.Error(err.Error()) - http.Error(w, err.Error(), http.StatusBadRequest) - return - } + vars := mux.Vars(r) - err = client.DeleteShare(r.Context(), shareParams.Slug) + err := client.DeleteShare(r.Context(), vars["slug"]) if err != nil { logrus.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError)