Compare commits
3 Commits
b55c1f7d48
...
7ed63d94cc
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 7ed63d94cc | |
Derrick Hammer | c667c9509c | |
Derrick Hammer | 4988368b7c |
|
@ -417,6 +417,10 @@ func (a *AccountAPI) Routes() (*httprouter.Router, error) {
|
|||
AllowedMethods: []string{"*"},
|
||||
})
|
||||
|
||||
corsOptionsHandler := func(c jape.Context) {
|
||||
c.ResponseWriter.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
routes := map[string]jape.Handler{
|
||||
// Auth
|
||||
"POST /api/auth/ping": middleware.ApplyMiddlewares(a.ping, corsMw.Handler, pingAuthMw, middleware.ProxyMiddleware),
|
||||
|
@ -434,6 +438,26 @@ func (a *AccountAPI) Routes() (*httprouter.Router, error) {
|
|||
"POST /api/account/update-email": middleware.ApplyMiddlewares(a.updateEmail, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"POST /api/account/update-password": middleware.ApplyMiddlewares(a.updatePassword, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
|
||||
// CORS
|
||||
"OPTIONS /api/auth/ping": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/auth/login": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, loginAuthMw2fa, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/auth/register": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/auth/otp/validate": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/auth/logout": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
|
||||
"OPTIONS /api/account/verify-email": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/otp/verify": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/otp/disable": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/password-reset/request": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/password-reset/confirm": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/update-email": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account/update-password": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
|
||||
// Get Routes
|
||||
"OPTIONS /api/upload-limit": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/account": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
"OPTIONS /api/auth/otp/generate": middleware.ApplyMiddlewares(corsOptionsHandler, corsMw.Handler, authMw, middleware.ProxyMiddleware),
|
||||
|
||||
"GET /*path": middleware.ApplyMiddlewares(getHandler, corsMw.Handler),
|
||||
}
|
||||
|
||||
|
|
49
api/s5/s5.go
49
api/s5/s5.go
|
@ -169,17 +169,17 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
|
|||
|
||||
tusHandler := BuildS5TusApi(authMw, s.tusHandler)
|
||||
|
||||
tusOptionsHandler := func(c jape.Context) {
|
||||
corsOptionsHandler := func(c jape.Context) {
|
||||
c.ResponseWriter.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
tusCors := BuildTusCors()
|
||||
|
||||
wrappedTusHandler := middleware.ApplyMiddlewares(tusOptionsHandler, tusCors, authMw)
|
||||
wrappedTusHandler := middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, tusCors, authMw)
|
||||
|
||||
debugCors := cors.Default()
|
||||
|
||||
uploadCors := cors.New(cors.Options{
|
||||
defaultCors := cors.New(cors.Options{
|
||||
AllowOriginFunc: func(origin string) bool {
|
||||
return true
|
||||
},
|
||||
|
@ -190,20 +190,20 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
|
|||
|
||||
routes := map[string]jape.Handler{
|
||||
// Account API
|
||||
"GET /s5/account/register": s.accountRegisterChallenge,
|
||||
"POST /s5/account/register": s.accountRegister,
|
||||
"GET /s5/account/login": s.accountLoginChallenge,
|
||||
"POST /s5/account/login": s.accountLogin,
|
||||
"GET /s5/account": middleware.ApplyMiddlewares(s.accountInfo, authMw),
|
||||
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.accountStats, authMw),
|
||||
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.accountPinsBinary, authMw),
|
||||
"GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, authMw),
|
||||
"GET /s5/account/register": middleware.ApplyMiddlewares(s.accountRegisterChallenge, middleware.ProxyMiddleware),
|
||||
"POST /s5/account/register": middleware.ApplyMiddlewares(s.accountRegister, middleware.ProxyMiddleware),
|
||||
"GET /s5/account/login": middleware.ApplyMiddlewares(s.accountLoginChallenge, middleware.ProxyMiddleware),
|
||||
"POST /s5/account/login": middleware.ApplyMiddlewares(s.accountLogin, middleware.ProxyMiddleware),
|
||||
"GET /s5/account": middleware.ApplyMiddlewares(s.accountInfo, middleware.ProxyMiddleware, authMw),
|
||||
"GET /s5/account/stats": middleware.ApplyMiddlewares(s.accountStats, middleware.ProxyMiddleware, authMw),
|
||||
"GET /s5/account/pins.bin": middleware.ApplyMiddlewares(s.accountPinsBinary, middleware.ProxyMiddleware, authMw),
|
||||
"GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, middleware.ProxyMiddleware, authMw),
|
||||
|
||||
// Upload API
|
||||
"POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, uploadCors.Handler, authMw),
|
||||
"POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, uploadCors.Handler, authMw),
|
||||
"OPTIONS /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, uploadCors.Handler, authMw),
|
||||
"OPTIONS /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, uploadCors.Handler, authMw),
|
||||
"POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
|
||||
"POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
|
||||
"OPTIONS /s5/upload": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
|
||||
"OPTIONS /s5/upload/directory": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
|
||||
|
||||
// Tus API
|
||||
"POST /s5/upload/tus": tusHandler,
|
||||
|
@ -214,22 +214,25 @@ func (s *S5API) Routes() (*httprouter.Router, error) {
|
|||
"OPTIONS /s5/upload/tus/:id": wrappedTusHandler,
|
||||
|
||||
// Download API
|
||||
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.downloadBlob, authMw),
|
||||
"GET /s5/metadata/:cid": s.downloadMetadata,
|
||||
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.downloadFile, cors.Default().Handler),
|
||||
"GET /s5/blob/:cid": middleware.ApplyMiddlewares(s.downloadBlob, middleware.ProxyMiddleware, authMw),
|
||||
"GET /s5/metadata/:cid": s.downloadMetadata,
|
||||
"GET /s5/download/:cid": middleware.ApplyMiddlewares(s.downloadFile, middleware.ProxyMiddleware, defaultCors.Handler),
|
||||
"OPTIONS /s5/blob/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler, authMw),
|
||||
"OPTIONS /s5/metadata/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler),
|
||||
"OPTIONS /s5/download/:cid": middleware.ApplyMiddlewares(corsOptionsHandler, middleware.ProxyMiddleware, defaultCors.Handler),
|
||||
|
||||
// Pins API
|
||||
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.accountPin, authMw),
|
||||
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.accountPinDelete, authMw),
|
||||
"POST /s5/pin/:cid": middleware.ApplyMiddlewares(s.accountPin, middleware.ProxyMiddleware, authMw),
|
||||
"DELETE /s5/delete/:cid": middleware.ApplyMiddlewares(s.accountPinDelete, middleware.ProxyMiddleware, authMw),
|
||||
|
||||
// Debug API
|
||||
"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),
|
||||
|
||||
// Registry API
|
||||
"GET /s5/registry": middleware.ApplyMiddlewares(s.registryQuery, authMw),
|
||||
"POST /s5/registry": middleware.ApplyMiddlewares(s.registrySet, authMw),
|
||||
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.registrySubscription, authMw),
|
||||
"GET /s5/registry": middleware.ApplyMiddlewares(s.registryQuery, middleware.ProxyMiddleware, authMw),
|
||||
"POST /s5/registry": middleware.ApplyMiddlewares(s.registrySet, middleware.ProxyMiddleware, authMw),
|
||||
"GET /s5/registry/subscription": middleware.ApplyMiddlewares(s.registrySubscription, middleware.ProxyMiddleware, authMw),
|
||||
}
|
||||
|
||||
routes, err := swagger.Swagger(swagSpec, routes)
|
||||
|
|
Loading…
Reference in New Issue