Files
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

48 lines
1023 B
Go

package configser
import (
"context"
"hkdj-web-server/app/appg"
"hkdj-web-server/pub/common/ipaddr"
"strings"
"github.com/gin-gonic/gin"
)
// ClientIPFromCtx 从 gin 请求上下文解析客户端 IP。
func ClientIPFromCtx(ctx context.Context) string {
c, ok := ctx.(*gin.Context)
if !ok || c == nil {
return ""
}
return ipaddr.ResolveClientIP(c)
}
// IsOverseasIP 与 m3u8 TS 域名判断一致:按 v4/v6 库识别是否海外。
func IsOverseasIP(ip string) bool {
ip = strings.TrimSpace(ip)
if ip == "" {
return false
}
detector := appg.DetectorV6
if ipaddr.IsIPv4(ip) {
detector = appg.DetectorV4
}
if detector == nil {
return false
}
ok, _ := detector.IsOverseasIP(ip)
return ok
}
// GetAppImageCdn 海外 IP 且配置了 imgAppUsCdn 时用海外图床,否则用 imgAppCdn。
func GetAppImageCdn(ip string) string {
cfg := GetConfigInfo()
if IsOverseasIP(ip) {
if us := strings.TrimSpace(cfg.ImgAppUsCdn); us != "" {
return us
}
}
return strings.TrimSpace(cfg.ImgCdn)
}