fix(openflare): mmdb 国家名节点在世界地图使用正确质心

- 从 world-geo 生成国家质心表,Server 在仅有 ISO/国家名时补全 geo 坐标
- 全球态势板在缺少经纬度时按 geo_name 解析质心,避免 fallback 到美国
This commit is contained in:
ryan
2026-06-20 19:46:33 +08:00
parent 498a9ed3ff
commit 8751c0dee3
6 changed files with 978 additions and 0 deletions
+20
View File
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/Rain-kl/Wavelet/internal/model"
pkggeoip "github.com/Rain-kl/Wavelet/pkg/geoip"
"github.com/Rain-kl/Wavelet/pkg/logger"
)
@@ -40,7 +41,26 @@ func ApplyNodeGeoFromIP(ctx context.Context, node *model.OpenFlareNode, rawIP st
if info.Latitude != nil && info.Longitude != nil {
node.GeoLatitude = cloneCoordinate(info.Latitude)
node.GeoLongitude = cloneCoordinate(info.Longitude)
return
}
applyCountryCentroid(node, info.ISOCode, info.Name)
}
func applyCountryCentroid(node *model.OpenFlareNode, isoCode, name string) {
if lat, lon, ok := pkggeoip.CountryCentroidByISO(isoCode); ok {
node.GeoLatitude = cloneFloat(lat)
node.GeoLongitude = cloneFloat(lon)
return
}
if lat, lon, ok := pkggeoip.CountryCentroidByName(name); ok {
node.GeoLatitude = cloneFloat(lat)
node.GeoLongitude = cloneFloat(lon)
}
}
func cloneFloat(value float64) *float64 {
cloned := value
return &cloned
}
func cloneCoordinate(value *float64) *float64 {