Skip to content

Commit

Permalink
Moved GM_deleteValue(config.keyPrefix + '_openAItoken') from `dataP…
Browse files Browse the repository at this point in the history
…rocess.text()` to `deleteOpenAIcookies()` for consolidation ↞ [auto-sync from `adamlui/chatgpt-apps/bravegpt`]
  • Loading branch information
adamlui authored and kudo-sync-bot committed Jun 24, 2024
1 parent 629f2f2 commit 2c53778
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions chatgpt/bravegpt/bravegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2024.6.24.1
// @version 2024.6.24.3
// @license MIT
// @icon https://media.bravegpt.com/images/icons/bravegpt/icon48.png?0a9e287
// @icon64 https://media.bravegpt.com/images/icons/bravegpt/icon64.png?0a9e287
Expand Down Expand Up @@ -1157,6 +1157,7 @@ setTimeout(async () => {
}

function deleteOpenAIcookies() {
GM_deleteValue(config.keyPrefix + '_openAItoken')
if (getUserscriptManager() != 'Tampermonkey') return
GM_cookie.list({ url: openAIendpoints.auth }, (cookies, error) => {
if (!error) { for (const cookie of cookies) {
Expand Down Expand Up @@ -1342,11 +1343,12 @@ setTimeout(async () => {
get.related.api = api.pick(get.related)
if (!get.related.api) return // no more proxy APIs left untried

if (!config.proxyAPIenabled) // init OpenAI key
// Init OpenAI key
if (get.related.api == 'OpenAI')
config.openAIkey = await Promise.race([getOpenAItoken(), new Promise(reject => setTimeout(reject, 3000))])
else setTimeout(() => { // try diff API after 7s of no response
if (get.related.status != 'done')
api.tryNew(get.related, 'timeout') }, 7000)

// Try diff API after 7s of no response
setTimeout(() => { if (get.related.status != 'done') api.tryNew(get.related, 'timeout') }, 7000)

return new Promise((resolve, reject) => {
const rqPrompt = 'Show a numbered list of queries related to this one:\n\n' + query
Expand Down Expand Up @@ -1418,8 +1420,8 @@ setTimeout(async () => {
consoleErr('Response text', resp.responseText)
if (config.proxyAPIenabled && caller.status != 'done')
api.tryNew(caller)
else if (resp.status == 401 && !config.proxyAPIenabled) {
GM_deleteValue(config.keyPrefix + '_openAItoken') ; appAlert('login') }
else if (resp.status == 401 && !config.proxyAPIenabled)
appAlert('login')
else if (resp.status == 403)
appAlert(config.proxyAPIenabled ? ['proxyNotWorking', 'suggestOpenAI'] : 'checkCloudflare')
else if (resp.status == 429)
Expand Down

0 comments on commit 2c53778

Please sign in to comment.