From 03301a47c043ea868eec952398d6ae0086715b01 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 17 Apr 2022 16:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96IPBox=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/default/servers/ipbox/index.go | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/internal/web/actions/default/servers/ipbox/index.go b/internal/web/actions/default/servers/ipbox/index.go index 95027933..88d94e56 100644 --- a/internal/web/actions/default/servers/ipbox/index.go +++ b/internal/web/actions/default/servers/ipbox/index.go @@ -20,8 +20,6 @@ func (this *IndexAction) Init() { func (this *IndexAction) RunGet(params struct { Ip string - - Partition int32 `default:"-1"` }) { this.Data["ip"] = params.Ip @@ -104,36 +102,37 @@ func (this *IndexAction) RunGet(params struct { this.Data["publicBlackIPLists"] = publicBlackIPListMaps // 访问日志 - accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - Partition: params.Partition, - Day: timeutil.Format("Ymd"), - Ip: params.Ip, - Size: 20, - }) - if err != nil { - this.ErrorPage(err) - return - } - var accessLogs = accessLogsResp.HttpAccessLogs - if len(accessLogs) == 0 { - // 查询昨天 - accessLogsResp, err = this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ - Partition: params.Partition, - Day: timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1)), - Ip: params.Ip, - Size: 20, - }) + var hasAccessLogs = false + for _, day := range []string{timeutil.Format("Ymd"), timeutil.Format("Ymd", time.Now().AddDate(0, 0, -1))} { + partitionsResp, err := this.RPC().HTTPAccessLogRPC().FindHTTPAccessLogPartitions(this.AdminContext(), &pb.FindHTTPAccessLogPartitionsRequest{Day: day}) if err != nil { this.ErrorPage(err) return } - accessLogs = accessLogsResp.HttpAccessLogs + for _, partition := range partitionsResp.ReversePartitions { + accessLogsResp, err := this.RPC().HTTPAccessLogRPC().ListHTTPAccessLogs(this.AdminContext(), &pb.ListHTTPAccessLogsRequest{ + Partition: partition, + Day: day, + Ip: params.Ip, + Size: 20, + }) + if err != nil { + this.ErrorPage(err) + return + } - if len(accessLogs) == 0 { - accessLogs = []*pb.HTTPAccessLog{} + var accessLogs = accessLogsResp.HttpAccessLogs + if len(accessLogs) > 0 { + this.Data["accessLogs"] = accessLogs + hasAccessLogs = true + break + } } } - this.Data["accessLogs"] = accessLogs + + if !hasAccessLogs { + this.Data["accessLogs"] = []interface{}{} + } this.Show() }