Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 3d1cbae

Browse files
committed
fix(api/comment_get): use frontend pageSize config
Signed-off-by: qwqcode <[email protected]>
1 parent 0cab1cc commit 3d1cbae

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

artalk-go.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ frontend:
283283
default: "mp"
284284
# 评论分页
285285
pagination:
286+
# 每页评论数
287+
pageSize: 20
286288
# 加载更多模式 (关闭则使用分页条)
287289
readMore: true
288290
# 滚动加载

http/comment_get.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func (a *action) Get(c echo.Context) error {
5252
// use site
5353
UseSite(c, &p.SiteName, &p.SiteID, &p.SiteAll)
5454

55+
// handle params
56+
UseCfgFrontend(&p)
57+
5558
// find page
5659
var page model.Page
5760
if !p.SiteAll {

http/comment_get_query.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package http
22

33
import (
4+
"fmt"
5+
"reflect"
6+
"strconv"
47
"strings"
58

9+
"github.com/ArtalkJS/ArtalkGo/config"
610
"github.com/ArtalkJS/ArtalkGo/model"
711
"github.com/labstack/echo/v4"
812
"gorm.io/gorm"
@@ -209,3 +213,29 @@ func prependPinnedComments(a *action, c echo.Context, p ParamsGet, comments *[]m
209213
// prepend
210214
*comments = append(pinnedComments, filteredComments...)
211215
}
216+
217+
// 处理来自配置文件的 fronted 配置项
218+
func UseCfgFrontend(p *ParamsGet) {
219+
feConf := config.Instance.Frontend
220+
if feConf == nil || reflect.ValueOf(feConf).Kind() != reflect.Map {
221+
return
222+
}
223+
224+
// pagination
225+
(func() {
226+
pagination, isExist := feConf["pagination"]
227+
if !isExist {
228+
return
229+
}
230+
if reflect.ValueOf(pagination).Kind() != reflect.Map {
231+
return
232+
}
233+
234+
// pagination.pageSize
235+
cfgPageSizeStr := fmt.Sprintf("%v", pagination.(Map)["pageSize"])
236+
confPageSize, err := strconv.Atoi(cfgPageSizeStr)
237+
if err == nil && confPageSize > 0 {
238+
p.Limit = confPageSize
239+
}
240+
})()
241+
}

0 commit comments

Comments
 (0)