From 4c8f1d4fd2d1ba366388d7c05347a5d18177ba3b Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Wed, 8 Mar 2023 12:27:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ip=E5=BD=92=E5=B1=9E=E5=9C=B0=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/common.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/utils/common.js b/utils/common.js index a8f8327..13b5bdc 100644 --- a/utils/common.js +++ b/utils/common.js @@ -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 } } -} \ No newline at end of file +}