Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

fix:api余额查询不会走代理 #1204

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions service/src/chatgpt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt'
import { SocksProxyAgent } from 'socks-proxy-agent'
import httpsProxyAgent from 'https-proxy-agent'
import fetch from 'node-fetch'
import axios from 'axios'
import { sendResponse } from '../utils'
import { isNotEmptyString } from '../utils/is'
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
Expand Down Expand Up @@ -149,9 +150,9 @@ async function fetchBalance() {

try {
// 获取已使用量
const useResponse = await fetch(urlUsage, { headers })
const usageData = await useResponse.json() as BalanceResponse
const usage = Math.round(usageData.total_usage) / 100
const useResponse = await axios.get(urlUsage, { headers })
const usageData = await useResponse.data.total_usage ?? 0
const usage = Math.round(usageData) / 100
return Promise.resolve(usage ? `$${usage}` : '-')
}
catch {
Expand Down