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

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

View File

@ -6,6 +6,6 @@ VUE_APP_ADMIN_USER=admin
VUE_APP_ADMIN_PASS=admin123 VUE_APP_ADMIN_PASS=admin123
VUE_APP_KEY_PREFIX=GeekAI_DEV_ VUE_APP_KEY_PREFIX=GeekAI_DEV_
VUE_APP_TITLE="Geek-AI 创作系统" 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_DOCS_URL=https://docs.geekai.me
VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai

View File

@ -1,6 +1,6 @@
VUE_APP_API_HOST= VUE_APP_API_HOST=
VUE_APP_WS_HOST= VUE_APP_WS_HOST=
VUE_APP_KEY_PREFIX=GeekAI_ 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_DOCS_URL=https://docs.geekai.me
VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai VUE_APP_GIT_URL=https://github.com/yangjian102621/geekai