mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
fix: 微调Bing画图
This commit is contained in:
parent
fde029cd91
commit
2bf3a636a6
1 changed files with 19 additions and 45 deletions
|
|
@ -22,9 +22,9 @@ export default class BingDrawClient {
|
||||||
async getImages (prompt, e) {
|
async getImages (prompt, e) {
|
||||||
let urlEncodedPrompt = encodeURIComponent(prompt)
|
let urlEncodedPrompt = encodeURIComponent(prompt)
|
||||||
let url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=4&FORM=GENCRE`
|
let url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=4&FORM=GENCRE`
|
||||||
let fetchOptions = {
|
let d = Math.ceil(Math.random() * 255)
|
||||||
method: 'POST',
|
let randomIp = '141.11.138.' + d
|
||||||
headers: {
|
let headers = {
|
||||||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||||
'accept-language': 'en-US,en;q=0.9',
|
'accept-language': 'en-US,en;q=0.9',
|
||||||
'cache-control': 'max-age=0',
|
'cache-control': 'max-age=0',
|
||||||
|
|
@ -32,8 +32,13 @@ export default class BingDrawClient {
|
||||||
referrer: 'https://www.bing.com/images/create/',
|
referrer: 'https://www.bing.com/images/create/',
|
||||||
origin: 'https://www.bing.com',
|
origin: 'https://www.bing.com',
|
||||||
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
|
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
|
||||||
cookie: this.opts.cookies || `_U=${this.opts.userToken}`
|
cookie: this.opts.cookies || `_U=${this.opts.userToken}`,
|
||||||
},
|
'x-forwarded-for': randomIp
|
||||||
|
}
|
||||||
|
// headers['x-forwarded-for'] = '141.11.138.30'
|
||||||
|
let fetchOptions = {
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
redirect: 'manual'
|
redirect: 'manual'
|
||||||
}
|
}
|
||||||
if (Config.proxy) {
|
if (Config.proxy) {
|
||||||
|
|
@ -46,22 +51,9 @@ export default class BingDrawClient {
|
||||||
}
|
}
|
||||||
if (response.status !== 302) {
|
if (response.status !== 302) {
|
||||||
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||||
let response3 = await fetch(url, {
|
let response3 = await fetch(url, fetchOptions)
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
||||||
'accept-language': 'en-US,en;q=0.9',
|
|
||||||
'cache-control': 'max-age=0',
|
|
||||||
'content-type': 'application/x-www-form-urlencoded',
|
|
||||||
referrer: 'https://www.bing.com/images/create/',
|
|
||||||
origin: 'https://www.bing.com',
|
|
||||||
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
|
|
||||||
cookie: this.opts.cookies || `_U=${this.opts.userToken}`
|
|
||||||
},
|
|
||||||
redirect: 'manual'
|
|
||||||
})
|
|
||||||
if (response3.status !== 302) {
|
if (response3.status !== 302) {
|
||||||
throw new Error(await response3.text())
|
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||||
}
|
}
|
||||||
response = response3
|
response = response3
|
||||||
}
|
}
|
||||||
|
|
@ -69,16 +61,7 @@ export default class BingDrawClient {
|
||||||
let requestId = redirectUrl.split('id=')[1]
|
let requestId = redirectUrl.split('id=')[1]
|
||||||
// 模拟跳转
|
// 模拟跳转
|
||||||
await fetch(`${this.opts.baseUrl}${redirectUrl}`, {
|
await fetch(`${this.opts.baseUrl}${redirectUrl}`, {
|
||||||
headers: {
|
headers
|
||||||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
||||||
'accept-language': 'en-US,en;q=0.9',
|
|
||||||
'cache-control': 'max-age=0',
|
|
||||||
'content-type': 'application/x-www-form-urlencoded',
|
|
||||||
referrer: 'https://www.bing.com/images/create/',
|
|
||||||
origin: 'https://www.bing.com',
|
|
||||||
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
|
|
||||||
cookie: this.opts.cookies || `_U=${this.opts.userToken}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
let pollingUrl = `${this.opts.baseUrl}/images/create/async/results/${requestId}?q=${urlEncodedPrompt}`
|
let pollingUrl = `${this.opts.baseUrl}/images/create/async/results/${requestId}?q=${urlEncodedPrompt}`
|
||||||
logger.info({ pollingUrl })
|
logger.info({ pollingUrl })
|
||||||
|
|
@ -90,16 +73,7 @@ export default class BingDrawClient {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let r = await fetch(pollingUrl, {
|
let r = await fetch(pollingUrl, {
|
||||||
headers: {
|
headers
|
||||||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
||||||
'accept-language': 'en-US,en;q=0.9',
|
|
||||||
'cache-control': 'max-age=0',
|
|
||||||
'content-type': 'application/x-www-form-urlencoded',
|
|
||||||
referrer: 'https://www.bing.com/images/create/',
|
|
||||||
origin: 'https://www.bing.com',
|
|
||||||
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
|
|
||||||
cookie: this.opts.cookies || `_U=${this.opts.userToken}`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
let rText = await r.text()
|
let rText = await r.text()
|
||||||
if (rText) {
|
if (rText) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue