diff --git a/internal/web/web.go b/internal/web/web.go index 76d6c49..62bb9dd 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -70,6 +70,31 @@ func StartWebserver(addr string, client client.Client, username, password string json.NewEncoder(w).Encode(shares) }).Methods("GET") + r.HandleFunc("/api/share/{slug:[a-zA-Z0-9]{6}}", func(w http.ResponseWriter, r *http.Request) { + if !checkAuth(w, r, username, password) { + return + } + + vars := mux.Vars(r) + slug := vars["slug"] + + share, err := client.GetShare(r.Context(), slug) + + if err != nil { + logrus.Error(err.Error()) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if share == nil { + http.NotFound(w, r) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(share) + }).Methods("GET") + r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) { if !checkAuth(w, r, username, password) { return