feat: add initial tusJwtResponseWriter bones so we can append the auth_token to tus urls

This commit is contained in:
Derrick Hammer 2024-01-20 07:54:24 -05:00
parent 4378da70da
commit a2051acff1
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 26 additions and 1 deletions

View File

@ -101,6 +101,18 @@ func AuthMiddleware(handler jape.Handler, portal interfaces.Portal) jape.Handler
})(handler)
}
type tusJwtResponseWriter struct {
http.ResponseWriter
}
func (w *tusJwtResponseWriter) WriteHeader(statusCode int) {
// Check if this is the specific route and status
if statusCode == http.StatusCreated {
// Modify the response or add query arguments as needed
}
w.ResponseWriter.WriteHeader(statusCode)
}
func BuildS5TusApi(portal interfaces.Portal) jape.Handler {
// Wrapper function for AuthMiddleware to fit the MiddlewareFunc signature
@ -127,8 +139,21 @@ func BuildS5TusApi(portal interfaces.Portal) jape.Handler {
})(h)
}
injectJwt := func(h jape.Handler) jape.Handler {
return jape.Adapt(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
res := w
if r.Method == http.MethodPatch || r.Method == http.MethodPost {
res = &tusJwtResponseWriter{ResponseWriter: w}
}
h.ServeHTTP(res, r)
})
})(h)
}
// Apply the middlewares to the tusJapeHandler
tusHandler := ApplyMiddlewares(tusJapeHandler, stripPrefix, authMiddlewareFunc, protocolMiddleware)
tusHandler := ApplyMiddlewares(tusJapeHandler, injectJwt, stripPrefix, authMiddlewareFunc, protocolMiddleware)
return tusHandler
}