mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: 画图重试5次
This commit is contained in:
parent
f2f77235b1
commit
9a8db9577a
1 changed files with 21 additions and 11 deletions
|
|
@ -61,18 +61,28 @@ export default class BingDrawClient {
|
||||||
if (Config.proxy) {
|
if (Config.proxy) {
|
||||||
fetchOptions.agent = proxy(Config.proxy)
|
fetchOptions.agent = proxy(Config.proxy)
|
||||||
}
|
}
|
||||||
let response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
let success = false
|
||||||
let res = await response.text()
|
let retry = 5
|
||||||
if (res.toLowerCase().indexOf('this prompt has been blocked') > -1) {
|
let response
|
||||||
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
|
while (!success && retry >= 0) {
|
||||||
}
|
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||||
if (response.status !== 302) {
|
let res = await response.text()
|
||||||
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
if (res.toLowerCase().indexOf('this prompt has been blocked') > -1) {
|
||||||
let response3 = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
|
||||||
if (response3.status !== 302) {
|
|
||||||
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
|
||||||
}
|
}
|
||||||
response = response3
|
if (response.status !== 302) {
|
||||||
|
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||||
|
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||||
|
}
|
||||||
|
if (response.status === 302) {
|
||||||
|
success = true
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
retry--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!success) {
|
||||||
|
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||||
}
|
}
|
||||||
let redirectUrl = response.headers.get('Location').replace('&nfy=1', '')
|
let redirectUrl = response.headers.get('Location').replace('&nfy=1', '')
|
||||||
let requestId = redirectUrl.split('id=')[1]
|
let requestId = redirectUrl.split('id=')[1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue