mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Update a number of dependencies (incl. CVE fixes) Includes some dependencies that were upgraded in #4106 as well as a few more dependencies. Some deps that have been upgraded had CVEs. Notably, upgrades deprecated dependencies such as: - `github.com/go-chi/chi` (replaced with `/v5`) - `github.com/gofrs/uuid` (replaced with `/v5`) - `github.com/hashicorp/golang-lru` (replaced with `/v2` which uses generics) * Upgraded a few more deps * lint * reverted yaml library to v2 * remove unnecessary mod replace * Update chromedp Fixes #3733
46 lines
963 B
Go
46 lines
963 B
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/stashapp/stash/internal/manager"
|
|
)
|
|
|
|
type downloadsRoutes struct{}
|
|
|
|
func getDownloadsRoutes() chi.Router {
|
|
return downloadsRoutes{}.Routes()
|
|
}
|
|
|
|
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))
|
|
})
|
|
}
|