refactor: need to use middleware package

This commit is contained in:
Derrick Hammer 2024-01-19 17:08:05 -05:00
parent 5b1838a63b
commit 2e64b56115
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 18 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package api package api
import ( import (
"git.lumeweb.com/LumeWeb/portal/api/middleware"
"git.lumeweb.com/LumeWeb/portal/api/s5" "git.lumeweb.com/LumeWeb/portal/api/s5"
"git.lumeweb.com/LumeWeb/portal/interfaces" "git.lumeweb.com/LumeWeb/portal/interfaces"
"git.lumeweb.com/LumeWeb/portal/protocols" "git.lumeweb.com/LumeWeb/portal/protocols"
@ -27,35 +28,38 @@ func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol
} }
func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Handler { func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Handler {
tusHandler := middleware.BuildS5TusApi(portal)
return map[string]jape.Handler{ return map[string]jape.Handler{
// Account API // Account API
"GET /s5/account/register": h.AccountRegisterChallenge, "GET /s5/account/register": h.AccountRegisterChallenge,
"POST /s5/account/register": h.AccountRegister, "POST /s5/account/register": h.AccountRegister,
"GET /s5/account/login": h.AccountLoginChallenge, "GET /s5/account/login": h.AccountLoginChallenge,
"POST /s5/account/login": h.AccountLogin, "POST /s5/account/login": h.AccountLogin,
"GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal), "GET /s5/account": middleware.AuthMiddleware(h.AccountInfo, portal),
"GET /s5/account/stats": s5.AuthMiddleware(h.AccountStats, portal), "GET /s5/account/stats": middleware.AuthMiddleware(h.AccountStats, portal),
"GET /s5/account/pins.bin": s5.AuthMiddleware(h.AccountPins, portal), "GET /s5/account/pins.bin": middleware.AuthMiddleware(h.AccountPins, portal),
// Upload API // Upload API
"POST /s5/upload": s5.AuthMiddleware(h.SmallFileUpload, portal), "POST /s5/upload": middleware.AuthMiddleware(h.SmallFileUpload, portal),
"POST /s5/upload/directory": s5.AuthMiddleware(h.DirectoryUpload, portal), "POST /s5/upload/directory": middleware.AuthMiddleware(h.DirectoryUpload, portal),
// Download API // Download API
"GET /s5/blob/:cid": s5.AuthMiddleware(h.DownloadBlob, portal), "GET /s5/blob/:cid": middleware.AuthMiddleware(h.DownloadBlob, portal),
"GET /s5/metadata/:cid": h.DownloadMetadata, "GET /s5/metadata/:cid": h.DownloadMetadata,
// Pins API // Pins API
"POST /s5/pin/:cid": s5.AuthMiddleware(h.AccountPin, portal), "POST /s5/pin/:cid": middleware.AuthMiddleware(h.AccountPin, portal),
"DELETE /s5/delete/:cid": s5.AuthMiddleware(h.AccountPinDelete, portal), "DELETE /s5/delete/:cid": middleware.AuthMiddleware(h.AccountPinDelete, portal),
// Debug API // Debug API
"GET /s5/debug/download_urls/:cid": s5.AuthMiddleware(h.DebugDownloadUrls, portal), "GET /s5/debug/download_urls/:cid": middleware.AuthMiddleware(h.DebugDownloadUrls, portal),
"GET /s5/debug/storage_locations/:hash": s5.AuthMiddleware(h.DebugStorageLocations, portal), "GET /s5/debug/storage_locations/:hash": middleware.AuthMiddleware(h.DebugStorageLocations, portal),
//Registry API // Registry API
"GET /s5/registry": s5.AuthMiddleware(h.RegistryQuery, portal), "GET /s5/registry": middleware.AuthMiddleware(h.RegistryQuery, portal),
"POST /s5/registry": s5.AuthMiddleware(h.RegistrySet, portal), "POST /s5/registry": middleware.AuthMiddleware(h.RegistrySet, portal),
"GET /s5/registry/subscription": s5.AuthMiddleware(h.RegistrySubscription, portal), "GET /s5/registry/subscription": middleware.AuthMiddleware(h.RegistrySubscription, portal),
} }
} }