mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 15:51:14 +00:00
feat: Enhance low resolution character retrieval with customizable page size
This commit is contained in:
@@ -349,6 +349,22 @@ func handleGetLowResolutionCharacters(c fiber.Ctx) error {
|
||||
return model.NewRequestError("Invalid page number")
|
||||
}
|
||||
|
||||
// 支持自定义页面大小,默认50,最大1000
|
||||
pageSizeStr := c.Query("page_size")
|
||||
if pageSizeStr == "" {
|
||||
pageSizeStr = "50"
|
||||
}
|
||||
pageSize, err := strconv.Atoi(pageSizeStr)
|
||||
if err != nil {
|
||||
return model.NewRequestError("Invalid page_size parameter")
|
||||
}
|
||||
if pageSize > 1000 {
|
||||
pageSize = 1000 // 限制最大页面大小
|
||||
}
|
||||
if pageSize < 1 {
|
||||
pageSize = 1
|
||||
}
|
||||
|
||||
maxWidthStr := c.Query("max_width")
|
||||
if maxWidthStr == "" {
|
||||
maxWidthStr = "800" // 默认最大宽度800px
|
||||
@@ -367,7 +383,7 @@ func handleGetLowResolutionCharacters(c fiber.Ctx) error {
|
||||
return model.NewRequestError("Invalid max_height parameter")
|
||||
}
|
||||
|
||||
characters, totalPages, err := service.GetLowResolutionCharacters(page, maxWidth, maxHeight)
|
||||
characters, totalPages, err := service.GetLowResolutionCharacters(page, pageSize, maxWidth, maxHeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -803,12 +803,16 @@ func UpdateCharacterImage(uid, resourceID, characterID, imageID uint) error {
|
||||
}
|
||||
|
||||
// GetLowResolutionCharacters 获取低清晰度的角色图片
|
||||
func GetLowResolutionCharacters(page int, maxWidth, maxHeight int) ([]model.LowResCharacterView, int, error) {
|
||||
const pageSize = 50 // 每页50个角色
|
||||
|
||||
func GetLowResolutionCharacters(page int, pageSize int, maxWidth, maxHeight int) ([]model.LowResCharacterView, int, error) {
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 50 // 默认每页50个角色
|
||||
}
|
||||
if pageSize > 1000 {
|
||||
pageSize = 1000 // 限制最大页面大小
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
|
||||
Reference in New Issue
Block a user