41 lines
836 B
Go
Raw Normal View History

2024-10-10 18:00:49 +08:00
package handler
import (
"github.com/loveuer/nf-disk/internal/manager"
"github.com/loveuer/nf-disk/internal/s3"
"github.com/loveuer/nf-disk/ndh"
)
2024-10-11 18:36:59 +08:00
func BucketFiles(c *ndh.Ctx) error {
2024-10-10 18:00:49 +08:00
type Req struct {
2024-10-11 18:03:09 +08:00
ConnId uint64 `json:"conn_id"`
Bucket string `json:"bucket"`
Prefix string `json:"prefix"`
2024-10-10 18:00:49 +08:00
}
var (
err error
req = new(Req)
client *s3.Client
2024-10-11 18:03:09 +08:00
list []*s3.ListFileRes
2024-10-10 18:00:49 +08:00
)
if err = c.ReqParse(req); err != nil {
return c.Send400(err.Error())
}
if req.ConnId == 0 || req.Bucket == "" {
return c.Send400(req, "缺少参数")
}
if _, client, err = manager.Manager.Use(req.ConnId); err != nil {
return c.Send500(err.Error())
}
2024-10-11 18:03:09 +08:00
if list, err = client.ListFile(c.Context(), req.Bucket, req.Prefix); err != nil {
return c.Send500(err.Error())
}
return c.Send200(map[string]any{"list": list})
2024-10-10 18:00:49 +08:00
}