mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-07 21:50:25 +08:00
WAF规则中国家/地区、省份、城市、ISP增加候选项检索和选择
This commit is contained in:
43
internal/web/actions/default/ui/countryOptions.go
Normal file
43
internal/web/actions/default/ui/countryOptions.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CountryOptionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CountryOptionsAction) RunPost(params struct{}) {
|
||||
countriesResp, err := this.RPC().RegionCountryRPC().FindAllEnabledRegionCountries(this.AdminContext(), &pb.FindAllEnabledRegionCountriesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countryMaps = []maps.Map{}
|
||||
for _, country := range countriesResp.RegionCountries {
|
||||
if country.Codes == nil {
|
||||
country.Codes = []string{}
|
||||
}
|
||||
|
||||
var letter = ""
|
||||
if len(country.Pinyin) > 0 && len(country.Pinyin) > 0 && len(country.Pinyin[0]) > 0 {
|
||||
letter = strings.ToUpper(country.Pinyin[0][:1])
|
||||
}
|
||||
|
||||
countryMaps = append(countryMaps, maps.Map{
|
||||
"id": country.Id,
|
||||
"name": country.Name,
|
||||
"fullname": letter + " " + country.Name,
|
||||
"codes": country.Codes,
|
||||
})
|
||||
}
|
||||
this.Data["countries"] = countryMaps
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user