mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: 调整sydney token过期方式;画图调整增加成功概率
This commit is contained in:
parent
cc78143c0e
commit
3c437ddfc5
4 changed files with 85 additions and 59 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import fetch from 'node-fetch'
|
||||
import fetch, { FormData } from 'node-fetch'
|
||||
import { makeForwardMsg } from './common.js'
|
||||
import { Config } from './config.js'
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ export default class BingDrawClient {
|
|||
async getImages (prompt, e) {
|
||||
let urlEncodedPrompt = encodeURIComponent(prompt)
|
||||
let url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=4&FORM=GENCRE`
|
||||
let d = Math.ceil(Math.random() * 255)
|
||||
let randomIp = '141.11.138.' + d
|
||||
// let d = Math.ceil(Math.random() * 255)
|
||||
// let randomIp = '141.11.138.' + d
|
||||
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-language': 'en-US,en;q=0.9',
|
||||
|
|
@ -31,27 +31,44 @@ export default class BingDrawClient {
|
|||
'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',
|
||||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50',
|
||||
cookie: this.opts.cookies || `_U=${this.opts.userToken}`,
|
||||
'x-forwarded-for': randomIp
|
||||
// 'x-forwarded-for': randomIp,
|
||||
Dnt: '1',
|
||||
'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
|
||||
'sec-ch-ua-arch': '"x86"',
|
||||
'sec-ch-ua-bitness': '"64"',
|
||||
'sec-ch-ua-full-version': '"113.0.5672.126"',
|
||||
'sec-ch-ua-full-version-list': '"Google Chrome";v="113.0.5672.126", "Chromium";v="113.0.5672.126", "Not-A.Brand";v="24.0.0.0"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-model': '',
|
||||
'sec-ch-ua-platform': '"macOS"',
|
||||
'sec-ch-ua-platform-version': '"13.1.0"',
|
||||
'sec-fetch-dest': 'document',
|
||||
'sec-fetch-mode': 'navigate',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
'sec-fetch-user': '?1',
|
||||
'Referrer-Policy': 'origin-when-cross-origin',
|
||||
'x-edge-shopping-flag': '1'
|
||||
}
|
||||
// headers['x-forwarded-for'] = '141.11.138.30'
|
||||
let body = new FormData()
|
||||
body.append('q', prompt)
|
||||
body.append('qs', 'ds')
|
||||
let fetchOptions = {
|
||||
method: 'POST',
|
||||
headers,
|
||||
redirect: 'manual'
|
||||
headers
|
||||
}
|
||||
if (Config.proxy) {
|
||||
fetchOptions.agent = proxy(Config.proxy)
|
||||
}
|
||||
let response = await fetch(url, fetchOptions)
|
||||
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, fetchOptions)
|
||||
let response3 = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
if (response3.status !== 302) {
|
||||
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||
}
|
||||
|
|
@ -72,9 +89,7 @@ export default class BingDrawClient {
|
|||
if (found) {
|
||||
return
|
||||
}
|
||||
let r = await fetch(pollingUrl, {
|
||||
headers
|
||||
})
|
||||
let r = await fetch(pollingUrl, fetchOptions)
|
||||
let rText = await r.text()
|
||||
if (rText) {
|
||||
// logger.info(rText)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue