refactor: re-implement s5 routes
This commit is contained in:
parent
69b1938e87
commit
c4f0226d1a
16
api/s5.go
16
api/s5.go
|
@ -1,8 +1,10 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"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"
|
||||||
|
"go.sia.tech/jape"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -17,9 +19,19 @@ func NewS5() *S5API {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol) error {
|
func (s S5API) Initialize(portal interfaces.Portal, protocol interfaces.Protocol) error {
|
||||||
|
|
||||||
s5protocol := protocol.(*protocols.S5Protocol)
|
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
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
"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/libs5-go/types"
|
||||||
"git.lumeweb.com/LumeWeb/portal/db/models"
|
"git.lumeweb.com/LumeWeb/portal/db/models"
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
|
@ -19,10 +18,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
_ s5interface.HTTPHandler = (*HttpHandlerImpl)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errMultiformParse = "Error parsing multipart form"
|
errMultiformParse = "Error parsing multipart form"
|
||||||
errRetrievingFile = "Error retrieving the file"
|
errRetrievingFile = "Error retrieving the file"
|
||||||
|
@ -37,15 +32,15 @@ var (
|
||||||
errAccountGenerateChallengeErr = errors.New(errAccountGenerateChallenge)
|
errAccountGenerateChallengeErr = errors.New(errAccountGenerateChallenge)
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpHandlerImpl struct {
|
type HttpHandler struct {
|
||||||
portal interfaces.Portal
|
portal interfaces.Portal
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpHandler(portal interfaces.Portal) *HttpHandlerImpl {
|
func NewHttpHandler(portal interfaces.Portal) *HttpHandler {
|
||||||
return &HttpHandlerImpl{portal: portal}
|
return &HttpHandler{portal: portal}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) {
|
func (h *HttpHandler) SmallFileUpload(jc jape.Context) {
|
||||||
var rs io.ReadSeeker
|
var rs io.ReadSeeker
|
||||||
var bufferSize int64
|
var bufferSize int64
|
||||||
|
|
||||||
|
@ -159,7 +154,7 @@ func (h *HttpHandlerImpl) SmallFileUpload(jc *jape.Context) {
|
||||||
jc.Encode(map[string]string{"hash": cidStr})
|
jc.Encode(map[string]string{"hash": cidStr})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandlerImpl) AccountRegisterChallenge(jc *jape.Context) {
|
func (h *HttpHandler) AccountRegisterChallenge(jc jape.Context) {
|
||||||
var pubkey string
|
var pubkey string
|
||||||
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
if jc.DecodeForm("pubKey", &pubkey) != nil {
|
||||||
return
|
return
|
||||||
|
@ -201,17 +196,17 @@ func (h *HttpHandlerImpl) AccountRegisterChallenge(jc *jape.Context) {
|
||||||
jc.Encode(map[string]string{"challenge": base64.RawURLEncoding.EncodeToString(challenge)})
|
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
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandlerImpl) AccountLoginChallenge(context *jape.Context) {
|
func (h *HttpHandler) AccountLoginChallenge(context jape.Context) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HttpHandlerImpl) AccountLogin(context *jape.Context) {
|
func (h *HttpHandler) AccountLogin(context jape.Context) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
|
@ -1,16 +1,15 @@
|
||||||
package protocols
|
package protocols
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"fmt"
|
"fmt"
|
||||||
s5config "git.lumeweb.com/LumeWeb/libs5-go/config"
|
s5config "git.lumeweb.com/LumeWeb/libs5-go/config"
|
||||||
s5ed "git.lumeweb.com/LumeWeb/libs5-go/ed25519"
|
s5ed "git.lumeweb.com/LumeWeb/libs5-go/ed25519"
|
||||||
s5interfaces "git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
s5interfaces "git.lumeweb.com/LumeWeb/libs5-go/interfaces"
|
||||||
s5node "git.lumeweb.com/LumeWeb/libs5-go/node"
|
s5node "git.lumeweb.com/LumeWeb/libs5-go/node"
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
"git.lumeweb.com/LumeWeb/portal/protocols/s5"
|
bolt "go.etcd.io/bbolt"
|
||||||
bolt "go.etcd.io/bbolt"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -83,7 +82,6 @@ func (s *S5Protocol) Initialize(portal interfaces.Portal) error {
|
||||||
cfg.DB = db
|
cfg.DB = db
|
||||||
|
|
||||||
s.node = s5node.NewNode(cfg)
|
s.node = s5node.NewNode(cfg)
|
||||||
s.node.Services().HTTP().SetHttpHandler(s5.NewHttpHandler(s.portal))
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue