diff --git a/api/s5.go b/api/s5.go index b9c2f7f..8f7887f 100644 --- a/api/s5.go +++ b/api/s5.go @@ -1,8 +1,10 @@ package api import ( + "git.lumeweb.com/LumeWeb/portal/api/s5" "git.lumeweb.com/LumeWeb/portal/interfaces" "git.lumeweb.com/LumeWeb/portal/protocols" + "go.sia.tech/jape" ) var ( @@ -17,9 +19,19 @@ func NewS5() *S5API { } func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol) error { - s5protocol := protocol.(*protocols.S5Protocol) - registerProtocolSubdomain(portal, s5protocol.Node().Services().HTTP().GetHttpRouter(), "s5") + s5http := s5.NewHttpHandler(portal) + registerProtocolSubdomain(portal, s5protocol.Node().Services().HTTP().GetHttpRouter(getRoutes(s5http)), "s5") return nil } + +func getRoutes(h *s5.HttpHandler) map[string]jape.Handler { + return map[string]jape.Handler{ + "POST /s5/upload": h.SmallFileUpload, + "GET /account/register": h.AccountRegisterChallenge, + "POST /account/register": h.AccountRegister, + "GET /account/login": h.AccountLoginChallenge, + "POST /account/login": h.AccountLogin, + } +} diff --git a/protocols/s5/http.go b/api/s5/http.go similarity index 89% rename from protocols/s5/http.go rename to api/s5/http.go index 8c97440..9d07e32 100644 --- a/protocols/s5/http.go +++ b/api/s5/http.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "errors" "git.lumeweb.com/LumeWeb/libs5-go/encoding" - s5interface "git.lumeweb.com/LumeWeb/libs5-go/interfaces" "git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/portal/db/models" "git.lumeweb.com/LumeWeb/portal/interfaces" @@ -19,10 +18,6 @@ import ( "strings" ) -var ( - _ s5interface.HTTPHandler = (*HttpHandlerImpl)(nil) -) - const ( errMultiformParse = "Error parsing multipart form" errRetrievingFile = "Error retrieving the file" @@ -37,15 +32,15 @@ var ( errAccountGenerateChallengeErr = errors.New(errAccountGenerateChallenge) ) -type HttpHandlerImpl struct { +type HttpHandler struct { portal interfaces.Portal } -func NewHttpHandler(portal interfaces.Portal) *HttpHandlerImpl { - return &HttpHandlerImpl{portal: portal} +func NewHttpHandler(portal interfaces.Portal) *HttpHandler { + return &HttpHandler{portal: portal} } -func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) { +func (h *HttpHandler) SmallFileUpload(jc jape.Context) { var rs io.ReadSeeker var bufferSize int64 @@ -159,7 +154,7 @@ func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) { jc.Encode(map[string]string{"hash": cidStr}) } -func (h *HttpHandlerImpl) AccountRegisterChallenge(jc *jape.Context) { +func (h *HttpHandler) AccountRegisterChallenge(jc jape.Context) { var pubkey string if jc.DecodeForm("pubKey", &pubkey) != nil { return @@ -201,17 +196,17 @@ func (h *HttpHandlerImpl) AccountRegisterChallenge(jc *jape.Context) { jc.Encode(map[string]string{"challenge": base64.RawURLEncoding.EncodeToString(challenge)}) } -func (h *HttpHandlerImpl) AccountRegister(context *jape.Context) { +func (h *HttpHandler) AccountRegister(context jape.Context) { //TODO implement me panic("implement me") } -func (h *HttpHandlerImpl) AccountLoginChallenge(context *jape.Context) { +func (h *HttpHandler) AccountLoginChallenge(context jape.Context) { //TODO implement me panic("implement me") } -func (h *HttpHandlerImpl) AccountLogin(context *jape.Context) { +func (h *HttpHandler) AccountLogin(context jape.Context) { //TODO implement me panic("implement me") } diff --git a/protocols/s5.go b/protocols/s5.go index 61d61e2..68364b0 100644 --- a/protocols/s5.go +++ b/protocols/s5.go @@ -1,16 +1,15 @@ package protocols import ( - "crypto/ed25519" - "fmt" - s5config "git.lumeweb.com/LumeWeb/libs5-go/config" - s5ed "git.lumeweb.com/LumeWeb/libs5-go/ed25519" - s5interfaces "git.lumeweb.com/LumeWeb/libs5-go/interfaces" - s5node "git.lumeweb.com/LumeWeb/libs5-go/node" - "git.lumeweb.com/LumeWeb/portal/interfaces" - "git.lumeweb.com/LumeWeb/portal/protocols/s5" - bolt "go.etcd.io/bbolt" - "go.uber.org/zap" + "crypto/ed25519" + "fmt" + s5config "git.lumeweb.com/LumeWeb/libs5-go/config" + s5ed "git.lumeweb.com/LumeWeb/libs5-go/ed25519" + s5interfaces "git.lumeweb.com/LumeWeb/libs5-go/interfaces" + s5node "git.lumeweb.com/LumeWeb/libs5-go/node" + "git.lumeweb.com/LumeWeb/portal/interfaces" + bolt "go.etcd.io/bbolt" + "go.uber.org/zap" ) var ( @@ -83,7 +82,6 @@ func (s *S5Protocol) Initialize(portal interfaces.Portal) error { cfg.DB = db s.node = s5node.NewNode(cfg) - s.node.Services().HTTP().SetHttpHandler(s5.NewHttpHandler(s.portal)) return nil }