diff --git a/internal/client/client.go b/internal/client/client.go index f3c826c..e250bce 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -86,3 +86,7 @@ func (c *Client) CreateShare(ctx context.Context, key string) (*types.Share, err func (c *Client) GetObjectFromShare(ctx context.Context, share *types.Share) (s3.ObjectReader, error) { return c.s3.GetObject(ctx, share.Key) } + +func (c *Client) DeleteShare(ctx context.Context, slug string) error { + return c.db.DeleteShare(ctx, slug) +} diff --git a/internal/web/web.go b/internal/web/web.go index f8ad486..be48e04 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -14,6 +14,10 @@ type createShare struct { Key string `json:"key"` } +type deleteShare struct { + Slug string `json:"slug"` +} + func StartWebserver(addr string, client client.Client) error { r := mux.NewRouter() @@ -73,11 +77,23 @@ func StartWebserver(addr string, client client.Client) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(share) - }).Methods("POST") r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) { + //TODO: check auth + var shareParams deleteShare + err := json.NewDecoder(r.Body).Decode(&shareParams) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + err = client.DeleteShare(r.Context(), shareParams.Slug) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } }).Methods("DELETE") logrus.Info("Starting webserver")