1、bug修复

2、提交采集数据接口
This commit is contained in:
wangjian 2023-06-17 09:40:14 +08:00
parent a6cc6ba84d
commit 80612a99ab
3 changed files with 34 additions and 2 deletions

View File

@ -25,6 +25,15 @@ func (s HandlerService) GetList(c *gin.Context) (data interface{}, err error) {
repo := service.NewEdgeService(s.Logger)
var req proto.ListRequest
err = c.ShouldBindJSON(&req)
if req.Size < 1 {
req.Size = 20
}
if req.Size > 1000 {
req.Size = 1000
}
if req.Page < 1 {
req.Page = 1
}
if err != nil {
return nil, e.NewValidErr(err)
}

View File

@ -3,6 +3,12 @@ package proto
type ListRequest struct {
Path string `json:"path"`
IsIncludeSubdirectories bool `json:"isIncludeSubdirectories"`
BasePageList
}
type BasePageList struct {
Page int64 `json:"page,omitempty" form:"page"`
Size int64 `json:"pageSize,omitempty" form:"pageSize"`
}
type LabelRequest struct {

View File

@ -14,6 +14,7 @@ import (
"net/http"
"os"
"path"
"sort"
)
type PagingStruct struct {
@ -68,7 +69,10 @@ func (rp *repo) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.
if req.IsIncludeSubdirectories {
} else {
var files []os.DirEntry
var (
files []os.DirEntry
count int
)
files, err = os.ReadDir(req.Path)
if err != nil {
goto ReturnPoint
@ -88,10 +92,23 @@ func (rp *repo) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.
}
}
// 从小到大排序(稳定排序)
sort.SliceStable(list, func(i, j int) bool {
if list[i].Name < list[j].Name {
return true
}
return false
})
count = len(list)
if len(list) >= int(req.Page*req.Size) {
list = list[int((req.Page-1)*req.Size):int(req.Page*req.Size)]
} else {
list = list[int((req.Page-1)*req.Size):]
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp.Data = list
rsp = FillPaging(int64(count), req.Page, req.Size, list, rsp)
rsp.Err = err
return rsp, err
}