From 6f30eb79e6de3937550241dc51bbbe3045ebd077 Mon Sep 17 00:00:00 2001 From: zhilv Date: Fri, 27 Mar 2026 19:26:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/main.go | 2 ++ internal/ckwk/types.go | 14 ++++++++++++++ internal/handler/ckwk.go | 9 ++++++--- internal/handler/version.go | 18 ++++++++++++++++++ internal/router/router.go | 7 ++++--- 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 internal/handler/version.go diff --git a/cmd/main.go b/cmd/main.go index 51ad4b2..b4a375f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,6 +3,7 @@ package main import ( "ckwk/internal/router" "ckwk/pkg/log" + "fmt" "net/http" "go.uber.org/zap" @@ -11,6 +12,7 @@ import ( func main() { router := router.SetupRouter() + fmt.Printf("启动服务: http://local.kmux.cn:8080\n") if err := http.ListenAndServe( ":8080", router, diff --git a/internal/ckwk/types.go b/internal/ckwk/types.go index 0827e38..b3efa92 100644 --- a/internal/ckwk/types.go +++ b/internal/ckwk/types.go @@ -72,6 +72,20 @@ func GetRecords[T any](wk *WK, rType RecordType, courseID, page string) (*AllRec if !result.Status { return &result, fmt.Errorf("接口报错: %s", result.Msg) } + currentPage := result.PageInfo.Page + totalPages := result.PageInfo.PageCount + + for currentPage < totalPages { + nextPage := fmt.Sprint(currentPage + 1) + nextResult, err := GetRecords[T](wk, rType, courseID, nextPage) + if err != nil { + return nil, err + } + + result.List = append(result.List, nextResult.List...) + log.Debug("Page", zap.Int("currentPage", currentPage), zap.Int("Page", nextResult.PageInfo.Page)) + currentPage = nextResult.PageInfo.Page + } return &result, nil } diff --git a/internal/handler/ckwk.go b/internal/handler/ckwk.go index 248d5e5..beb241c 100644 --- a/internal/handler/ckwk.go +++ b/internal/handler/ckwk.go @@ -133,7 +133,7 @@ func (h *WKHandler) AllRecord(ctx *gin.Context) { req.Page = 1 } var list any - var pageInfo any + var pageInfo ckwk.PageInfo var err error // 根据类型调用不同的泛型方法 @@ -172,8 +172,11 @@ func (h *WKHandler) AllRecord(ctx *gin.Context) { } ctx.JSON(200, dto.Success(map[string]any{ - "list": list, - "page_info": pageInfo, + "list": list, + "page_info": map[string]any{ + "page": 1, + "pageSize": pageInfo.RecordsCount, + }, })) } diff --git a/internal/handler/version.go b/internal/handler/version.go new file mode 100644 index 0000000..fda5924 --- /dev/null +++ b/internal/handler/version.go @@ -0,0 +1,18 @@ +package handler + +import ( + "ckwk/internal/conf" + "ckwk/internal/dto" + + "github.com/gin-gonic/gin" +) + +func Version(ctx *gin.Context) { + ctx.JSON(200, dto.Success(map[string]string{ + "Version": conf.Version, + "BuildAt": conf.BuildAt, + "GitAuthor": conf.GitAuthor, + "GitEmail": conf.GitEmail, + "GitCommit": conf.GitCommit, + })) +} diff --git a/internal/router/router.go b/internal/router/router.go index c0763e3..72ede2b 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -24,9 +24,9 @@ func SetupRouter() *gin.Engine { } r := gin.Default() r.Use(cors.New(cors.Config{ - AllowOrigins: []string{"*://*", "http://localhost:5173"}, + AllowOrigins: []string{"*.kmux.cn"}, AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"}, - AllowHeaders: []string{"*", "X-Session-Id"}, + AllowHeaders: []string{"X-Session-Id"}, ExposeHeaders: []string{"Content-Length"}, AllowCredentials: true, MaxAge: 12 * time.Hour, @@ -42,11 +42,12 @@ func SetupRouter() *gin.Engine { distHTTP := http.FS(dist) r.StaticFS("/js", http.FS(mustSub(dist, "js"))) r.StaticFS("/assets", http.FS(mustSub(dist, "assets"))) - r.StaticFileFS("/favicon.ico", "favicon.ico", distHTTP) + r.StaticFileFS("/favicon.png", "favicon.png", distHTTP) api := r.Group("/api") { api.POST("/login", wkHandler.Login) + api.Any("/version", handler.Version) v1 := api.Group("/v1") { v1.GET("/host", wkHandler.Host)