refactor: add proxy middleware to add routes

This commit is contained in:
Derrick Hammer 2024-03-19 15:40:03 -04:00
parent c667c9509c
commit 7ed63d94cc
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 23 deletions

View File

@ -175,7 +175,7 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
tusCors := BuildTusCors() tusCors := BuildTusCors()
wrappedTusHandler := middleware.ApplyMiddlewares(corsOptionsHandler, tusCors, authMw) wrappedTusHandler := middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, tusCors, authMw)
debugCors := cors.Default() debugCors := cors.Default()
@ -190,20 +190,20 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
routes := map[string]jape.Handler{ routes := map[string]jape.Handler{
// Account API // Account API
"GET /s5/account/register": s.accountRegisterChallenge, "GET /s5/account/register": middleware.ApplyMiddlewares(s.accountRegisterChallenge, middleware.ProxyMiddleware),
"POST /s5/account/register": s.accountRegister, "POST /s5/account/register": middleware.ApplyMiddlewares(s.accountRegister, middleware.ProxyMiddleware),
"GET /s5/account/login": s.accountLoginChallenge, "GET /s5/account/login": middleware.ApplyMiddlewares(s.accountLoginChallenge, middleware.ProxyMiddleware),
"POST /s5/account/login": s.accountLogin, "POST /s5/account/login": middleware.ApplyMiddlewares(s.accountLogin, middleware.ProxyMiddleware),
"GET /s5/account": middleware.ApplyMiddlewares(s.accountInfo, authMw), "GET /s5/account": middleware.ApplyMiddlewares(s.accountInfo, middleware.ProxyMiddleware, authMw),
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.accountStats, authMw), "GET /s5/account/stats": middleware.ApplyMiddlewares(s.accountStats, middleware.ProxyMiddleware, authMw),
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.accountPinsBinary, authMw), "GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.accountPinsBinary, middleware.ProxyMiddleware, authMw),
"GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, authMw), "GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, middleware.ProxyMiddleware, authMw),
// Upload API // Upload API
"POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, defaultCors.Handler, authMw), "POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
"POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, defaultCors.Handler, authMw), "POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
"OPTIONS /s5/upload": middleware.ApplyMiddlewares(corsOptionsHandler, defaultCors.Handler, authMw), "OPTIONS /s5/upload": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
"OPTIONS /s5/upload/directory": middleware.ApplyMiddlewares(corsOptionsHandler, defaultCors.Handler, authMw), "OPTIONS /s5/upload/directory": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
// Tus API // Tus API
"POST /s5/upload/tus": tusHandler, "POST /s5/upload/tus": tusHandler,
@ -214,25 +214,25 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
"OPTIONS /s5/upload/tus/:id": wrappedTusHandler, "OPTIONS /s5/upload/tus/:id": wrappedTusHandler,
// Download API // Download API
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.downloadBlob, authMw), "GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.downloadBlob, middleware.ProxyMiddleware, authMw),
"GET /s5/metadata/:cid": s.downloadMetadata, "GET /s5/metadata/:cid": s.downloadMetadata,
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.downloadFile, defaultCors.Handler), "GET /s5/download/:cid": middleware.ApplyMiddlewares(s.downloadFile, middleware.ProxyMiddleware, defaultCors.Handler),
"OPTIONS /s5/blob/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, defaultCors.Handler, authMw), "OPTIONS /s5/blob/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
"OPTIONS /s5/metadata/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, defaultCors.Handler), "OPTIONS /s5/metadata/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler),
"OPTIONS /s5/download/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, defaultCors.Handler), "OPTIONS /s5/download/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler),
// Pins API // Pins API
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.accountPin, authMw), "POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.accountPin, middleware.ProxyMiddleware, authMw),
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.accountPinDelete, authMw), "DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.accountPinDelete, middleware.ProxyMiddleware, authMw),
// Debug API // Debug API
"GET /s5/debug/download_urls/:cid": middleware.ApplyMiddlewares(s.debugDownloadUrls, middleware.ProxyMiddleware, debugCors.Handler), "GET /s5/debug/download_urls/:cid": middleware.ApplyMiddlewares(s.debugDownloadUrls, middleware.ProxyMiddleware, debugCors.Handler),
"GET /s5/debug/storage_locations/:hash": middleware.ApplyMiddlewares(s.debugStorageLocations, middleware.ProxyMiddleware, debugCors.Handler), "GET /s5/debug/storage_locations/:hash": middleware.ApplyMiddlewares(s.debugStorageLocations, middleware.ProxyMiddleware, debugCors.Handler),
// Registry API // Registry API
"GET /s5/registry": middleware.ApplyMiddlewares(s.registryQuery, authMw), "GET /s5/registry": middleware.ApplyMiddlewares(s.registryQuery, middleware.ProxyMiddleware, authMw),
"POST /s5/registry": middleware.ApplyMiddlewares(s.registrySet, authMw), "POST /s5/registry": middleware.ApplyMiddlewares(s.registrySet, middleware.ProxyMiddleware, authMw),
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.registrySubscription, authMw), "GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.registrySubscription, middleware.ProxyMiddleware, authMw),
} }
routes, err := swagger.Swagger(swagSpec, routes) routes, err := swagger.Swagger(swagSpec, routes)