mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-25 11:36:34 +08:00
88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
|
|
package log
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||
|
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||
|
|
"regexp"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
type HistoryAction struct {
|
||
|
|
actionutils.ParentAction
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *HistoryAction) Init() {
|
||
|
|
this.Nav("", "log", "")
|
||
|
|
this.SecondMenu("history")
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *HistoryAction) RunGet(params struct {
|
||
|
|
ServerId int64
|
||
|
|
Day string
|
||
|
|
|
||
|
|
RequestId string
|
||
|
|
HasError int
|
||
|
|
}) {
|
||
|
|
if len(params.Day) == 0 {
|
||
|
|
params.Day = timeutil.Format("Y-m-d")
|
||
|
|
}
|
||
|
|
|
||
|
|
this.Data["path"] = this.Request.URL.Path
|
||
|
|
this.Data["day"] = params.Day
|
||
|
|
this.Data["accessLogs"] = []interface{}{}
|
||
|
|
this.Data["hasError"] = params.HasError
|
||
|
|
|
||
|
|
day := params.Day
|
||
|
|
if len(day) > 0 && regexp.MustCompile(`\d{4}-\d{2}-\d{2}`).MatchString(day) {
|
||
|
|
day = strings.ReplaceAll(day, "-", "")
|
||
|
|
size := int64(10)
|
||
|
|
|
||
|
|
this.Data["hasError"] = params.HasError
|
||
|
|
|
||
|
|
resp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||
|
|
RequestId: params.RequestId,
|
||
|
|
ServerId: params.ServerId,
|
||
|
|
HasError: params.HasError > 0,
|
||
|
|
Day: day,
|
||
|
|
Size: size,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
this.ErrorPage(err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(resp.AccessLogs) == 0 {
|
||
|
|
this.Data["accessLogs"] = []interface{}{}
|
||
|
|
} else {
|
||
|
|
this.Data["accessLogs"] = resp.AccessLogs
|
||
|
|
}
|
||
|
|
this.Data["hasMore"] = resp.HasMore
|
||
|
|
this.Data["nextRequestId"] = resp.RequestId
|
||
|
|
|
||
|
|
// 上一个requestId
|
||
|
|
this.Data["hasPrev"] = false
|
||
|
|
this.Data["lastRequestId"] = ""
|
||
|
|
if len(params.RequestId) > 0 {
|
||
|
|
this.Data["hasPrev"] = true
|
||
|
|
prevResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{
|
||
|
|
RequestId: params.RequestId,
|
||
|
|
ServerId: params.ServerId,
|
||
|
|
HasError: params.HasError > 0,
|
||
|
|
Day: day,
|
||
|
|
Size: size,
|
||
|
|
Reverse: true,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
this.ErrorPage(err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if int64(len(prevResp.AccessLogs)) == size {
|
||
|
|
this.Data["lastRequestId"] = prevResp.RequestId
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.Show()
|
||
|
|
}
|