redirect bingai to cloudflare challenge if needed

This commit is contained in:
James Feng Cao 2023-06-19 20:55:00 +08:00
parent 63077ffe8f
commit 2c2f15bfa9
2 changed files with 10 additions and 1 deletions

View file

@ -235,6 +235,15 @@ async function createChat(theChatType) {
try {
let url = URLTrue(magicUrl,'turing/conversation/create');
let res = await fetch(url);
if(!res.ok){
if(res.headers.has('cf-mitigated')){
let challengeUrl = `${magicUrl}/challenge?`+location.href;
location.href=challengeUrl;
return;
}
mes = `Error code: ${res.status} ${res.statusText}`;
break;
}
let resjson = await res.json();
if (!resjson.result || resjson.result.value != 'Success') {
mes = resjson;