mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +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) {
|
||||
fetchOptions.agent = proxy(Config.proxy)
|
||||
}
|
||||
let response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
let res = await response.text()
|
||||
if (res.toLowerCase().indexOf('this prompt has been blocked') > -1) {
|
||||
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
|
||||
}
|
||||
if (response.status !== 302) {
|
||||
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||
let response3 = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
if (response3.status !== 302) {
|
||||
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||
let success = false
|
||||
let retry = 5
|
||||
let response
|
||||
while (!success && retry >= 0) {
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
let res = await response.text()
|
||||
if (res.toLowerCase().indexOf('this prompt has been blocked') > -1) {
|
||||
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
|
||||
}
|
||||
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 requestId = redirectUrl.split('id=')[1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue