1.4.5.2
This commit is contained in:
179
EdgeUser/internal/web/actions/default/dashboard/index.go
Normal file
179
EdgeUser/internal/web/actions/default/dashboard/index.go
Normal file
@@ -0,0 +1,179 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 是否开启了CDN
|
||||
registerConfig, err := configloaders.LoadRegisterConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if registerConfig != nil && !registerConfig.CDNIsOn {
|
||||
if registerConfig.NSIsOn {
|
||||
this.RedirectURL("/dashboard/ns")
|
||||
return
|
||||
}
|
||||
|
||||
// 显示空白
|
||||
this.View("@blank")
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
|
||||
// 是否需要审核和实名认证
|
||||
this.Data["isVerified"] = this.Context.GetBool("isVerified")
|
||||
this.Data["isIdentified"] = this.Context.GetBool("isIdentified")
|
||||
|
||||
if !configloaders.RequireVerification() {
|
||||
this.Data["isVerified"] = true
|
||||
}
|
||||
if !configloaders.RequireIdentity() {
|
||||
this.Data["isIdentified"] = true
|
||||
}
|
||||
|
||||
// 查看UI配置
|
||||
uiConfig, _ := configloaders.LoadUIConfig()
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": true,
|
||||
"showBandwidthCharts": true,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit,
|
||||
}
|
||||
if uiConfig != nil {
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": uiConfig.ShowTrafficCharts,
|
||||
"showBandwidthCharts": uiConfig.ShowBandwidthCharts,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit, // 强制使用比特单位
|
||||
}
|
||||
}
|
||||
|
||||
// 是否需要激活邮箱
|
||||
var userResp *pb.FindEnabledUserResponse
|
||||
this.Data["emailVerificationMessage"] = ""
|
||||
if registerConfig != nil && registerConfig.EmailVerification.IsOn {
|
||||
// 尚未激活
|
||||
verificationResp, err := this.RPC().UserEmailVerificationRPC().FindLatestUserEmailVerification(this.UserContext(), &pb.FindLatestUserEmailVerificationRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if verificationResp.UserEmailVerification != nil {
|
||||
this.Data["emailVerificationMessage"] = "电子邮箱等待激活,请及时激活。"
|
||||
} else if registerConfig.EmailVerification.ShowNotice {
|
||||
// 尚未绑定
|
||||
var userErr error
|
||||
userResp, userErr = this.RPC().UserRPC().FindEnabledUser(this.UserContext(), &pb.FindEnabledUserRequest{UserId: this.UserId()})
|
||||
if userErr != nil {
|
||||
this.ErrorPage(userErr)
|
||||
return
|
||||
}
|
||||
if userResp.User != nil && len(userResp.User.VerifiedEmail) == 0 {
|
||||
this.Data["emailVerificationMessage"] = "尚未绑定电子邮箱,请点此绑定。"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 是否需要验证手机号
|
||||
this.Data["mobileVerificationMessage"] = ""
|
||||
if registerConfig != nil && registerConfig.MobileVerification.IsOn && registerConfig.MobileVerification.ShowNotice {
|
||||
// 尚未绑定
|
||||
if userResp == nil {
|
||||
var userErr error
|
||||
userResp, userErr = this.RPC().UserRPC().FindEnabledUser(this.UserContext(), &pb.FindEnabledUserRequest{UserId: this.UserId()})
|
||||
if userErr != nil {
|
||||
this.ErrorPage(userErr)
|
||||
return
|
||||
}
|
||||
}
|
||||
if userResp.User != nil && len(userResp.User.VerifiedMobile) == 0 {
|
||||
this.Data["mobileVerificationMessage"] = "尚未绑定手机号码,请点此绑定。"
|
||||
}
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct{}) {
|
||||
// 查看UI配置
|
||||
uiConfig, _ := configloaders.LoadUIConfig()
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": true,
|
||||
"showBandwidthCharts": true,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit,
|
||||
}
|
||||
if uiConfig != nil {
|
||||
this.Data["uiConfig"] = maps.Map{
|
||||
"showTrafficCharts": uiConfig.ShowTrafficCharts,
|
||||
"showBandwidthCharts": uiConfig.ShowBandwidthCharts,
|
||||
"bandwidthUnit": systemconfigs.BandwidthUnitBit, // 强制使用比特单位
|
||||
}
|
||||
}
|
||||
|
||||
dashboardResp, err := this.RPC().UserRPC().ComposeUserDashboard(this.UserContext(), &pb.ComposeUserDashboardRequest{UserId: this.UserId()})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var monthlyPeekBandwidthBytes = dashboardResp.MonthlyPeekBandwidthBytes
|
||||
var dailyPeekBandwidthBytes = dashboardResp.DailyPeekBandwidthBytes
|
||||
monthlyPeekBandwidthBytes *= 8
|
||||
dailyPeekBandwidthBytes *= 8
|
||||
this.Data["dashboard"] = maps.Map{
|
||||
"countServers": dashboardResp.CountServers,
|
||||
"monthlyTrafficBytes": numberutils.FormatBytes(dashboardResp.MonthlyTrafficBytes),
|
||||
"monthlyPeekBandwidthBytes": numberutils.FormatBits(monthlyPeekBandwidthBytes),
|
||||
"dailyTrafficBytes": numberutils.FormatBytes(dashboardResp.DailyTrafficBytes),
|
||||
"dailyPeekBandwidthBytes": numberutils.FormatBits(dailyPeekBandwidthBytes),
|
||||
}
|
||||
|
||||
// 每日流量统计
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range dashboardResp.DailyTrafficStats {
|
||||
var infoMap = maps.Map{
|
||||
"bytes": stat.Bytes,
|
||||
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
|
||||
"countRequests": stat.CountRequests,
|
||||
}
|
||||
if uiConfig.ShowCacheInfoInTrafficCharts {
|
||||
infoMap["cachedBytes"] = stat.CachedBytes
|
||||
infoMap["countCachedRequests"] = stat.CountCachedRequests
|
||||
}
|
||||
statMaps = append(statMaps, infoMap)
|
||||
}
|
||||
this.Data["dailyTrafficStats"] = statMaps
|
||||
}
|
||||
|
||||
// 每日峰值带宽统计
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range dashboardResp.DailyPeekBandwidthStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"bytes": stat.Bytes,
|
||||
"day": stat.Day[4:6] + "月" + stat.Day[6:] + "日",
|
||||
})
|
||||
}
|
||||
this.Data["dailyPeekBandwidthStats"] = statMaps
|
||||
}
|
||||
|
||||
this.Data["bandwidthPercentile"] = dashboardResp.BandwidthPercentile
|
||||
this.Data["bandwidthPercentileBits"] = dashboardResp.BandwidthPercentileBits
|
||||
|
||||
this.Success()
|
||||
}
|
||||
18
EdgeUser/internal/web/actions/default/dashboard/init.go
Normal file
18
EdgeUser/internal/web/actions/default/dashboard/init.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth("")).
|
||||
Data("teaMenu", "dashboard").
|
||||
Prefix("/dashboard").
|
||||
GetPost("", new(IndexAction)).
|
||||
Get("/ns", new(NsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
67
EdgeUser/internal/web/actions/default/dashboard/ns.go
Normal file
67
EdgeUser/internal/web/actions/default/dashboard/ns.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type NsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *NsAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *NsAction) RunGet(params struct{}) {
|
||||
// 是否开启了CDN
|
||||
registerConfig, err := configloaders.LoadRegisterConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if registerConfig != nil && !registerConfig.NSIsOn {
|
||||
// 显示空白
|
||||
this.View("@blank")
|
||||
this.Show()
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := this.RPC().NSRPC().ComposeNSUserBoard(this.UserContext(), &pb.ComposeNSUserBoardRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var planName = ""
|
||||
if resp.NsUserPlan != nil && resp.NsUserPlan.NsPlan != nil {
|
||||
planName = resp.NsUserPlan.NsPlan.Name
|
||||
}
|
||||
|
||||
this.Data["board"] = maps.Map{
|
||||
"countDomains": resp.CountNSDomains,
|
||||
"countRecords": resp.CountNSRecords,
|
||||
"countRoutes": resp.CountNSRoutes,
|
||||
"planName": planName,
|
||||
}
|
||||
|
||||
// 域名排行
|
||||
{
|
||||
var statMaps = []maps.Map{}
|
||||
for _, stat := range resp.TopNSDomainStats {
|
||||
statMaps = append(statMaps, maps.Map{
|
||||
"domainId": stat.NsDomainId,
|
||||
"domainName": stat.NsDomainName,
|
||||
"countRequests": stat.CountRequests,
|
||||
"bytes": stat.Bytes,
|
||||
})
|
||||
}
|
||||
this.Data["topDomainStats"] = statMaps
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user