kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
Fix double call to refreshSession() on 403
rodzic
1090fd8a89
commit
bfa0a90a12
|
@ -32,6 +32,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
|
||||||
protected _browser: Browser
|
protected _browser: Browser
|
||||||
protected _page: Page
|
protected _page: Page
|
||||||
protected _proxyServer: string
|
protected _proxyServer: string
|
||||||
|
protected _isRefreshing: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new client for automating the ChatGPT webapp.
|
* Creates a new client for automating the ChatGPT webapp.
|
||||||
|
@ -95,6 +96,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
|
||||||
this._nopechaKey = nopechaKey
|
this._nopechaKey = nopechaKey
|
||||||
this._executablePath = executablePath
|
this._executablePath = executablePath
|
||||||
this._proxyServer = proxyServer
|
this._proxyServer = proxyServer
|
||||||
|
this._isRefreshing = false
|
||||||
|
|
||||||
if (!this._email) {
|
if (!this._email) {
|
||||||
const error = new types.ChatGPTError('ChatGPT invalid email')
|
const error = new types.ChatGPTError('ChatGPT invalid email')
|
||||||
|
@ -280,7 +282,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.endsWith('/conversation')) {
|
if (url.endsWith('/conversation')) {
|
||||||
if (status === 403) {
|
if (status === 403 && !this._isRefreshing) {
|
||||||
await this.refreshSession()
|
await this.refreshSession()
|
||||||
}
|
}
|
||||||
} else if (url.endsWith('api/auth/session')) {
|
} else if (url.endsWith('api/auth/session')) {
|
||||||
|
@ -327,6 +329,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
|
||||||
* Attempts to handle 403 errors by refreshing the page.
|
* Attempts to handle 403 errors by refreshing the page.
|
||||||
*/
|
*/
|
||||||
async refreshSession() {
|
async refreshSession() {
|
||||||
|
this._isRefreshing = true
|
||||||
console.log(`ChatGPT "${this._email}" session expired (403); refreshing...`)
|
console.log(`ChatGPT "${this._email}" session expired (403); refreshing...`)
|
||||||
try {
|
try {
|
||||||
if (!this._minimize) {
|
if (!this._minimize) {
|
||||||
|
@ -372,6 +375,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
|
||||||
`ChatGPT "${this._email}" error refreshing session`,
|
`ChatGPT "${this._email}" error refreshing session`,
|
||||||
err.toString()
|
err.toString()
|
||||||
)
|
)
|
||||||
|
} finally {
|
||||||
|
this._isRefreshing = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue