v0.2.7: 修复Redis连接 + 启动管理后台
- 修复Redis认证 (配置密码) - 启动Python管理后台 (端口9531, 15个功能开关) - 统一版本号 0.2.7 - 更新docker-compose.yml (镜像版本/Redis URL/Admin服务)
This commit is contained in:
31
source_clean/src/cloud/ip-lookup.ts
Normal file
31
source_clean/src/cloud/ip-lookup.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* IP 归属地查询工具
|
||||
* 通过系统配置中的 IP 地理接口查询
|
||||
*/
|
||||
|
||||
import { getSystemConfig } from '../admin/system-config.service';
|
||||
|
||||
export async function lookupIpLocation(ip: string): Promise<string | null> {
|
||||
if (!ip || ip === '127.0.0.1' || ip === '::1' || ip.startsWith('192.168.') || ip.startsWith('10.')) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const apiUrlTemplate = getSystemConfig('ip_geo_api_url');
|
||||
if (!apiUrlTemplate) return null;
|
||||
const url = apiUrlTemplate.replace('{ip}', encodeURIComponent(ip));
|
||||
|
||||
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
|
||||
if (!res.ok) return null;
|
||||
const data = await res.json() as {
|
||||
code: number; sheng?: string; shi?: string; qu?: string;
|
||||
isp?: string; msg?: string; guo?: string;
|
||||
};
|
||||
if (data.code !== 200) return null;
|
||||
// Format: "四川 绵阳 江油 中国联通" — strip 省/市/区/州 suffixes for compact display
|
||||
const stripSuffix = (s: string | undefined) => s?.replace(/[省市州区]$/, '');
|
||||
const parts = [stripSuffix(data.sheng), stripSuffix(data.shi), stripSuffix(data.qu), data.isp].filter(Boolean);
|
||||
return parts.join(' ');
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user