get single share

This commit is contained in:
Djeeberjr 2022-05-17 01:14:45 +02:00
parent 361123baca
commit 0a74ecf651

View File

@ -70,6 +70,31 @@ func StartWebserver(addr string, client client.Client, username, password string
json.NewEncoder(w).Encode(shares) json.NewEncoder(w).Encode(shares)
}).Methods("GET") }).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) { r.HandleFunc("/api/share", func(w http.ResponseWriter, r *http.Request) {
if !checkAuth(w, r, username, password) { if !checkAuth(w, r, username, password) {
return return