[优化] geoip 工具

This commit is contained in:
ryan
2026-03-14 15:15:34 +08:00
parent 83f461efd0
commit f6dd7df55c
14 changed files with 761 additions and 7 deletions
+18
View File
@@ -5,6 +5,7 @@ import (
"atsflare/model"
"atsflare/service"
"atsflare/utils"
"atsflare/utils/geoip"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
@@ -62,6 +63,16 @@ func validateBooleanOption(key string, value string) error {
}
}
func validateGeoIPOption(key string, value string) error {
if key != "GeoIPProvider" {
return nil
}
if !geoip.IsValidProvider(value) {
return fmt.Errorf("%s 仅支持 disabled、mmdb、ip-api、geojs、ipinfo", key)
}
return nil
}
func validateOpenRestyOption(key string, value string) error {
trimmed := strings.TrimSpace(value)
@@ -250,6 +261,13 @@ func UpdateOption(c *gin.Context) {
})
return
}
if err = validateGeoIPOption(option.Key, option.Value); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
})
return
}
err = model.UpdateOption(option.Key, option.Value)
if err != nil {
c.JSON(http.StatusOK, gin.H{