portal/api/s5.go

57 lines
1.8 KiB
Go
Raw Normal View History

package api
import (
2024-01-16 16:42:50 +00:00
"git.lumeweb.com/LumeWeb/portal/api/s5"
"git.lumeweb.com/LumeWeb/portal/interfaces"
"git.lumeweb.com/LumeWeb/portal/protocols"
2024-01-16 16:42:50 +00:00
"go.sia.tech/jape"
)
var (
_ interfaces.API = (*S5API)(nil)
)
type S5API struct {
}
func NewS5() *S5API {
return &S5API{}
}
func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol) error {
s5protocol := protocol.(*protocols.S5Protocol)
2024-01-16 16:42:50 +00:00
s5http := s5.NewHttpHandler(portal)
2024-01-17 13:16:03 +00:00
registerProtocolSubdomain(portal, s5protocol.Node().Services().HTTP().GetHttpRouter(getRoutes(s5http, portal)), "s5")
return nil
}
2024-01-16 16:42:50 +00:00
2024-01-17 13:16:03 +00:00
func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Handler {
2024-01-16 16:42:50 +00:00
return map[string]jape.Handler{
2024-01-17 18:04:32 +00:00
// Account API
2024-01-16 18:57:33 +00:00
"GET /s5/account/register": h.AccountRegisterChallenge,
"POST /s5/account/register": h.AccountRegister,
"GET /s5/account/login": h.AccountLoginChallenge,
"POST /s5/account/login": h.AccountLogin,
2024-01-17 16:52:54 +00:00
"GET /s5/account": s5.AuthMiddleware(h.AccountInfo, portal),
2024-01-17 17:03:08 +00:00
"GET /s5/account/stats": s5.AuthMiddleware(h.AccountStats, portal),
"GET /s5/account/pins.bin": s5.AuthMiddleware(h.AccountPins, portal),
2024-01-17 18:04:32 +00:00
// Upload API
2024-01-17 19:46:37 +00:00
"POST /s5/upload": s5.AuthMiddleware(h.SmallFileUpload, portal),
"POST /s5/upload/directory": s5.AuthMiddleware(h.DirectoryUpload, portal),
2024-01-17 18:04:32 +00:00
// Pins API
2024-01-17 18:13:37 +00:00
"POST /s5/pin/:cid": s5.AuthMiddleware(h.AccountPin, portal),
2024-01-17 18:04:32 +00:00
"DELETE /s5/delete/:cid": s5.AuthMiddleware(h.AccountPinDelete, portal),
// Debug API
2024-01-17 21:59:53 +00:00
"GET /s5/debug/download_urls/:cid": s5.AuthMiddleware(h.DebugDownloadUrls, portal),
2024-01-17 21:05:11 +00:00
//Registry API
"GET /s5/registry": s5.AuthMiddleware(h.RegistryQuery, portal),
"POST /s5/registry": s5.AuthMiddleware(h.RegistrySet, portal),
"GET /s5/registry/subscription": s5.AuthMiddleware(h.RegistrySubscription, portal),
2024-01-16 16:42:50 +00:00
}
}