mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 23:59:45 +08:00
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:
parent
a5038ac844
commit
bb9b73557b
@ -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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user