mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: ip归属地不正确的问题
This commit is contained in:
parent
3e8789a367
commit
4c8f1d4fd2
1 changed files with 12 additions and 6 deletions
|
|
@ -360,11 +360,17 @@ export async function isCN () {
|
|||
if (await redis.get('CHATGPT:COUNTRY_CODE')) {
|
||||
return await redis.get('CHATGPT:COUNTRY_CODE') === 'CN'
|
||||
} else {
|
||||
let response = await fetch('https://ipinfo.io/country')
|
||||
let countryCode = await response.text()
|
||||
await redis.set('CHATGPT:COUNTRY_CODE', countryCode, { EX: 3600 * 24 * 7 })
|
||||
if (countryCode !== 'CN') {
|
||||
return false
|
||||
try {
|
||||
let response = await fetch('https://ipinfo.io/country')
|
||||
let countryCode = (await response.text()).trim()
|
||||
await redis.set('CHATGPT:COUNTRY_CODE', countryCode, { EX: 3600 * 24 * 7 })
|
||||
if (countryCode !== 'CN') {
|
||||
return false
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err)
|
||||
// 没拿到归属地默认CN
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue