fix: not signed问题

This commit is contained in:
葛胤池 2022-12-19 12:34:54 +08:00
parent 4df0addffb
commit 89dd029d0e

View file

@ -4,6 +4,7 @@ import StealthPlugin from 'puppeteer-extra-plugin-stealth'
import { getOpenAIAuth } from './openai-auth.js' import { getOpenAIAuth } from './openai-auth.js'
import delay from 'delay' import delay from 'delay'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
const chatUrl = 'https://chat.openai.com/chat' const chatUrl = 'https://chat.openai.com/chat'
let puppeteer = {} let puppeteer = {}
@ -126,9 +127,9 @@ export class ChatGPTPuppeteer extends Puppeteer {
} }
async init () { async init () {
if (this.inited) { // if (this.inited) {
return true // return true
} // }
try { try {
// this.browser = await getBrowser({ // this.browser = await getBrowser({
// captchaToken: this._captchaToken, // captchaToken: this._captchaToken,
@ -148,13 +149,22 @@ export class ChatGPTPuppeteer extends Puppeteer {
await this._page.goto(chatUrl, { await this._page.goto(chatUrl, {
waitUntil: 'networkidle2' waitUntil: 'networkidle2'
}) })
try {
while ((await this._page.title()).toLowerCase().indexOf('moment') > -1) { while ((await this._page.title()).toLowerCase().indexOf('moment') > -1) {
// if meet captcha // if meet captcha
// await this._page.solveRecaptchas() // await this._page.solveRecaptchas()
await delay(300) await delay(300)
} }
await delay(300) } catch (e) {
// navigation后获取title会报错报错说明已经在navigation了正合我意。
}
try {
await this._page.waitForNavigation({ timeout: 3000 })
} catch (e) {
logger.error(e)
}
if (!await this.getIsAuthenticated()) { if (!await this.getIsAuthenticated()) {
await redis.del('CHATGPT:RAW_COOKIES')
logger.info('需要登录,准备进行自动化登录') logger.info('需要登录,准备进行自动化登录')
await getOpenAIAuth({ await getOpenAIAuth({
email: this._email, email: this._email,
@ -167,7 +177,6 @@ export class ChatGPTPuppeteer extends Puppeteer {
} else { } else {
logger.info('无需登录') logger.info('无需登录')
} }
this.inited = true
} catch (err) { } catch (err) {
if (this.browser) { if (this.browser) {
await this.browser.close() await this.browser.close()
@ -929,6 +938,7 @@ export async function browserPostEventStream (
} }
} }
} }
function hasBom (buffer) { function hasBom (buffer) {
return BOM.every( return BOM.every(
(charCode, index) => buffer.charCodeAt(index) === charCode (charCode, index) => buffer.charCodeAt(index) === charCode