Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package trafficstats
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type SettingAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *SettingAction) Init() {
|
||||
this.Nav("", "", "setting")
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunGet(params struct{}) {
|
||||
this.Data["config"] = maps.Map{
|
||||
"bandwidthPercentile": systemconfigs.DefaultBandwidthPercentile,
|
||||
"defaultBandwidthDateRange": systemconfigs.DefaultBandwidthDateRangeCode,
|
||||
"bandwidthAlgo": systemconfigs.BandwidthAlgoSecondly,
|
||||
}
|
||||
userConfig, _ := configloaders.LoadUserUIConfig()
|
||||
if userConfig != nil {
|
||||
var config = userConfig.TrafficStats
|
||||
if config.BandwidthPercentile <= 0 {
|
||||
config.BandwidthPercentile = systemconfigs.DefaultBandwidthPercentile
|
||||
}
|
||||
if len(config.DefaultBandwidthDateRange) == 0 {
|
||||
config.DefaultBandwidthDateRange = systemconfigs.DefaultBandwidthDateRangeCode
|
||||
}
|
||||
if len(config.BandwidthAlgo) == 0 {
|
||||
config.BandwidthAlgo = systemconfigs.BandwidthAlgoSecondly
|
||||
}
|
||||
this.Data["config"] = config
|
||||
}
|
||||
|
||||
this.Data["dateRanges"] = systemconfigs.FindAllBandwidthDateRanges()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *SettingAction) RunPost(params struct {
|
||||
BandwidthPercentile int32
|
||||
DefaultBandwidthDateRange string
|
||||
BandwidthAlgo string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
config, err := configloaders.LoadUserUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if params.BandwidthPercentile < 0 {
|
||||
params.BandwidthPercentile = 0
|
||||
}
|
||||
if params.BandwidthPercentile > 100 {
|
||||
params.BandwidthPercentile = 95
|
||||
}
|
||||
|
||||
config.TrafficStats.BandwidthPercentile = params.BandwidthPercentile
|
||||
config.TrafficStats.DefaultBandwidthDateRange = params.DefaultBandwidthDateRange
|
||||
config.TrafficStats.BandwidthAlgo = params.BandwidthAlgo
|
||||
|
||||
err = configloaders.UpdateUserUIConfig(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 财务配置
|
||||
priceConfig, err := configloaders.LoadUserPriceConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if priceConfig != nil && priceConfig.DefaultBandwidthPriceConfig != nil && priceConfig.DefaultBandwidthPriceConfig.BandwidthAlgo != params.BandwidthAlgo {
|
||||
priceConfig.DefaultBandwidthPriceConfig.BandwidthAlgo = params.BandwidthAlgo
|
||||
err = configloaders.UpdateUserPriceConfig(priceConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user