wip: conn list
This commit is contained in:
@ -6,6 +6,8 @@ import (
|
||||
"github.com/loveuer/nf-disk/internal/model"
|
||||
"github.com/loveuer/nf-disk/internal/s3"
|
||||
"github.com/loveuer/nf-disk/ndh"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func ConnectionTest(c *ndh.Ctx) error {
|
||||
@ -86,11 +88,20 @@ func ConnectionCreate(c *ndh.Ctx) error {
|
||||
}
|
||||
|
||||
func ConnectionList(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
list = make([]*model.Connection, 0)
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
if err = db.Default.Session().Model(&model.Connection{}).
|
||||
Find(&list).
|
||||
Error; err != nil {
|
||||
@ -99,3 +110,56 @@ func ConnectionList(c *ndh.Ctx) error {
|
||||
|
||||
return c.Send200(map[string]any{"list": list})
|
||||
}
|
||||
|
||||
func ConnectionConnect(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Id uint64 `json:"id"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
conn = new(model.Connection)
|
||||
client *s3.Client
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
if err = db.Default.Session().Take(conn, req.Id).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return c.Send400(c, "不存在的连接")
|
||||
}
|
||||
|
||||
return c.Send500(nil)
|
||||
}
|
||||
|
||||
if client, err = s3.New(c.Context(), conn.Endpoint, conn.Access, conn.Key); err != nil {
|
||||
return c.Send500(err.Error())
|
||||
}
|
||||
|
||||
if err = manager.Register(conn, client); err != nil {
|
||||
return c.Send500(err.Error())
|
||||
}
|
||||
|
||||
return c.Send200(conn)
|
||||
}
|
||||
|
||||
func ConnectionBuckets(c *ndh.Ctx) error {
|
||||
type Req struct {
|
||||
Id uint64 `json:"id"`
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
req = new(Req)
|
||||
)
|
||||
|
||||
if err = c.ReqParse(req); err != nil {
|
||||
return c.Send400(nil, "参数错误")
|
||||
}
|
||||
|
||||
panic("implement me: ConnectionBuckets")
|
||||
}
|
||||
|
Reference in New Issue
Block a user