fix: use ipinfo lite API with token for IP country detection (#12312)

* fix: use ipinfo lite API with token for IP country detection

Switch from ipinfo.io/json to api.ipinfo.io/lite/me endpoint with
authentication token to improve reliability and avoid rate limiting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix: use country_code field from ipinfo lite API response

The lite API returns country_code instead of country field.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
beyondkmp 2026-01-06 17:33:19 +08:00 committed by GitHub
parent a5038ac844
commit bb9b73557b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,18 +13,13 @@ export async function getIpCountry(): Promise<string> {
const controller = new AbortController() const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 5000) const timeoutId = setTimeout(() => controller.abort(), 5000)
const ipinfo = await net.fetch('https://ipinfo.io/json', { const ipinfo = await net.fetch(`https://api.ipinfo.io/lite/me?token=2a42580355dae4`, {
signal: controller.signal, signal: controller.signal
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'Accept-Language': 'en-US,en;q=0.9'
}
}) })
clearTimeout(timeoutId) clearTimeout(timeoutId)
const data = await ipinfo.json() const data = await ipinfo.json()
const country = data.country || 'CN' const country = data.country_code || 'CN'
logger.info(`Detected user IP address country: ${country}`) logger.info(`Detected user IP address country: ${country}`)
return country return country
} catch (error) { } catch (error) {