changed delete share url

This commit is contained in:
Djeeberjr 2022-05-17 01:10:36 +02:00
parent f0254a6370
commit 05e438eb23

View File

@ -17,10 +17,6 @@ type createShare struct {
Key string `json:"key"` Key string `json:"key"`
} }
type deleteShare struct {
Slug string `json:"slug"`
}
func StartWebserver(addr string, client client.Client, username, password string) error { func StartWebserver(addr string, client client.Client, username, password string) error {
if username == "" || password == "" { if username == "" || password == "" {
return errors.New("API username and password must be set") 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) json.NewEncoder(w).Encode(share)
}).Methods("POST") }).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) { if !checkAuth(w, r, username, password) {
return return
} }
var shareParams deleteShare vars := mux.Vars(r)
err := json.NewDecoder(r.Body).Decode(&shareParams)
if err != nil {
logrus.Error(err.Error())
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
err = client.DeleteShare(r.Context(), shareParams.Slug) err := client.DeleteShare(r.Context(), vars["slug"])
if err != nil { if err != nil {
logrus.Error(err.Error()) logrus.Error(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)