Update conversation.js

获取对话列表等功能没有挂代理,导致功能失效
This commit is contained in:
2445164645 2023-02-25 21:55:28 +08:00 committed by GitHub
parent a46c69504a
commit 6c605e4db6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,13 +6,17 @@ export async function getConversations (qq = '') {
if (!accessToken) {
throw new Error('未绑定ChatGPT AccessToken请使用#chatgpt设置token命令绑定token')
}
let response = await fetch(`${Config.apiBaseUrl}/conversations?offset=0&limit=20`, {
let option01 = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
}
})
}
if (Config.proxy) {
option01.agent = new HttpsProxyAgent(Config.proxy)
}
let response = await fetch(`${Config.apiBaseUrl}/conversations?offset=0&limit=20`, option01)
let json = await response.text()
if (Config.debug) {
logger.mark(json)
@ -32,14 +36,18 @@ export async function getConversations (qq = '') {
if (cachedConversationLastMessage) {
map[item.id] = cachedConversationLastMessage
} else {
// 缓存中没有就去查官方api
let conversationDetailResponse = await fetch(`${Config.apiBaseUrl}/api/conversation/${item.id}`, {
let option02 = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
}
})
}
if (Config.proxy) {
option02.agent = new HttpsProxyAgent(Config.proxy)
}
// 缓存中没有就去查官方api
let conversationDetailResponse = await fetch(`${Config.apiBaseUrl}/api/conversation/${item.id}`, option02)
let conversationDetail = await conversationDetailResponse.text()
if (Config.debug) {
logger.mark('conversation detail for conversation ' + item.id, conversationDetail)
@ -101,13 +109,17 @@ export async function getLatestMessageIdByConversationId (conversationId) {
if (!accessToken) {
throw new Error('未绑定ChatGPT AccessToken请使用#chatgpt设置token命令绑定token')
}
let conversationDetailResponse = await fetch(`${Config.apiBaseUrl}/api/conversation/${conversationId}`, {
let option03 = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
}
})
}
if (Config.proxy) {
option03.agent = new HttpsProxyAgent(Config.proxy)
}
let conversationDetailResponse = await fetch(`${Config.apiBaseUrl}/api/conversation/${conversationId}`, option03)
let conversationDetail = await conversationDetailResponse.text()
if (Config.debug) {
logger.mark('conversation detail for conversation ' + conversationId, conversationDetail)
@ -129,14 +141,18 @@ export async function deleteConversation (conversationId) {
if (!accessToken) {
throw new Error('未绑定ChatGPT AccessToken请使用#chatgpt设置token命令绑定token')
}
let response = await fetch(`${Config.apiBaseUrl}/api/conversation/${conversationId}`, {
let option04 = {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + accessToken
},
body: JSON.stringify({ is_visible: false })
})
}
if (Config.proxy) {
option04.agent = new HttpsProxyAgent(Config.proxy)
}
let response = await fetch(`${Config.apiBaseUrl}/api/conversation/${conversationId}`, option04)
let responseText = await response.text()
return JSON.parse(responseText)
}