file list api support pagination

This commit is contained in:
RockYang 2024-09-10 15:24:36 +08:00
parent cdaf6fb9dc
commit 8b2e2d61af
3 changed files with 29 additions and 16 deletions

View File

@ -65,6 +65,8 @@ func (h *NetHandler) Upload(c *gin.Context) {
func (h *NetHandler) List(c *gin.Context) {
var data struct {
Urls []string `json:"urls,omitempty"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
@ -79,8 +81,20 @@ func (h *NetHandler) List(c *gin.Context) {
if len(data.Urls) > 0 {
session = session.Where("url IN ?", data.Urls)
}
session.Find(&items)
if len(items) > 0 {
// 统计总数
var total int64
session.Model(&model.File{}).Count(&total)
if data.Page > 0 && data.PageSize > 0 {
offset := (data.Page - 1) * data.PageSize
session = session.Offset(offset).Limit(data.PageSize)
}
err := session.Order("id desc").Find(&items).Error
if err != nil {
resp.ERROR(c, err.Error())
return
}
for _, v := range items {
var file vo.File
err := utils.CopyObject(v, &file)
@ -91,9 +105,8 @@ func (h *NetHandler) List(c *gin.Context) {
file.CreatedAt = v.CreatedAt.Unix()
files = append(files, file)
}
}
resp.SUCCESS(c, files)
resp.SUCCESS(c, vo.NewPage(total, data.Page, data.PageSize, files))
}
// Remove remove files

View File

@ -6,6 +6,6 @@ VUE_APP_ADMIN_USER=admin
VUE_APP_ADMIN_PASS=admin123
VUE_APP_KEY_PREFIX=GeekAI_DEV_
VUE_APP_TITLE="Geek-AI 创作系统"
VUE_APP_VERSION=v4.1.3
VUE_APP_VERSION=v4.1.4
VUE_APP_DOCS_URL=https://docs.geekai.me
VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai

View File

@ -1,6 +1,6 @@
VUE_APP_API_HOST=
VUE_APP_WS_HOST=
VUE_APP_KEY_PREFIX=GeekAI_
VUE_APP_VERSION=v4.1.3
VUE_APP_VERSION=v4.1.4
VUE_APP_DOCS_URL=https://docs.geekai.me
VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai