Selective export (#770)

This commit is contained in:
WithoutPants
2020-09-15 17:28:53 +10:00
committed by GitHub
parent 03f5e1a442
commit 03d4826c85
280 changed files with 40619 additions and 13035 deletions

View File

@@ -0,0 +1,41 @@
package api
import (
"context"
"net/http"
"github.com/go-chi/chi"
"github.com/stashapp/stash/pkg/manager"
)
type downloadsRoutes struct{}
func (rs downloadsRoutes) Routes() chi.Router {
r := chi.NewRouter()
r.Route("/{downloadHash}", func(r chi.Router) {
r.Use(downloadCtx)
r.Get("/{filename}", rs.file)
})
return r
}
func (rs downloadsRoutes) file(w http.ResponseWriter, r *http.Request) {
hash := r.Context().Value(downloadKey).(string)
if hash == "" {
http.Error(w, http.StatusText(404), 404)
return
}
manager.GetInstance().DownloadStore.Serve(hash, w, r)
}
func downloadCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
downloadHash := chi.URLParam(r, "downloadHash")
ctx := context.WithValue(r.Context(), downloadKey, downloadHash)
next.ServeHTTP(w, r.WithContext(ctx))
})
}