implemented delete share

This commit is contained in:
Djeeberjr 2022-05-09 15:36:43 +02:00
parent 65410d3210
commit d8726a7e6e
2 changed files with 21 additions and 1 deletions

View File

@ -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)
}

View File

@ -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")