Browse Source

调整 running_log 为 get 方式获取结果

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
35182cbdf4

+ 5 - 4
internal/backend/controllers/base/running_log.go

@@ -5,6 +5,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
 	"github.com/gin-gonic/gin"
 	"net/http"
+	"strconv"
 )
 
 func (cb ControllerBase) RunningLogHandler(c *gin.Context) {
@@ -14,14 +15,14 @@ func (cb ControllerBase) RunningLogHandler(c *gin.Context) {
 		cb.ErrorProcess(c, "RunningLogHandler", err)
 	}()
 
-	reqRunningLog := backend.ReqRunningLog{}
-	err = c.ShouldBindJSON(&reqRunningLog)
+	// 从缓存中拿到日志信息,拼接后返回
+	strLastFewTimes := c.DefaultQuery("the_last_few_times", "3")
+	lastFewTimes, err := strconv.Atoi(strLastFewTimes)
 	if err != nil {
 		return
 	}
-	// 从缓存中拿到日志信息,拼接后返回
 
-	tmpOnceLogs := log_helper.GetRecentOnceLogs(reqRunningLog.TheLastFewTimes)
+	tmpOnceLogs := log_helper.GetRecentOnceLogs(lastFewTimes)
 
 	replyOnceLog := backend.NewReplyRunningLog()
 	replyOnceLog.RecentLogs = append(replyOnceLog.RecentLogs, tmpOnceLogs...)

+ 1 - 1
internal/backend/routers/base_router.go

@@ -30,7 +30,7 @@ func InitRouter(router *gin.Engine, cronHelper *cron_helper.CronHelper) {
 
 	router.GET("/def-settings", cbBase.DefSettingsHandler)
 
-	router.POST("/running-log", middle.CheckAuth(), cbBase.RunningLogHandler)
+	router.GET("/running-log", middle.CheckAuth(), cbBase.RunningLogHandler)
 
 	// v1路由: /v1/xxx
 	GroupV1 := router.Group("/" + cbV1.GetVersion())

+ 4 - 0
internal/backend/ws_helper/client.go

@@ -275,6 +275,10 @@ func AuthReply(inType ws.AuthMessage) ([]byte, error) {
 // RunningLogReply 发送的 Running Log 数据,iPreSendLines 之前俺发送到第几条数据,则不发发送过的
 func RunningLogReply(log *log_hub.OnceLog, iPreSendLines ...int) ([][]byte, error) {
 
+	if log == nil {
+		return nil, nil
+	}
+
 	var outLogBytes = make([][]byte, 0)
 	var err error
 	var preSendLines = 0

+ 0 - 5
internal/types/backend/req_running_log.go

@@ -1,5 +0,0 @@
-package backend
-
-type ReqRunningLog struct {
-	TheLastFewTimes int `json:"the_last_few_times"` // 获取最后几次的运行日志,每次指的是一次字幕的扫描
-}