@@ -180,10 +180,23 @@ async function fetchBalance() {
180180 'Authorization' : `Bearer ${ OPENAI_API_KEY } ` ,
181181 'Content-Type' : 'application/json' ,
182182 }
183+ let socksAgent
184+ let httpsAgent
185+ if ( isNotEmptyString ( config . socksProxy ) ) {
186+ socksAgent = new SocksProxyAgent ( {
187+ hostname : config . socksProxy . split ( ':' ) [ 0 ] ,
188+ port : parseInt ( config . socksProxy . split ( ':' ) [ 1 ] ) ,
189+ userId : isNotEmptyString ( config . socksAuth ) ? config . socksAuth . split ( ':' ) [ 0 ] : undefined ,
190+ password : isNotEmptyString ( config . socksAuth ) ? config . socksAuth . split ( ':' ) [ 1 ] : undefined ,
191+ } )
192+ }
193+ else if ( isNotEmptyString ( config . httpsProxy ) ) {
194+ httpsAgent = new HttpsProxyAgent ( config . httpsProxy )
195+ }
183196
184197 try {
185198 // 获取API限额
186- let response = await fetch ( urlSubscription , { headers } )
199+ let response = await fetch ( urlSubscription , { agent : socksAgent === undefined ? httpsAgent : socksAgent , headers } )
187200 if ( ! response . ok ) {
188201 console . error ( '您的账户已被封禁,请登录OpenAI进行查看。' )
189202 return
@@ -192,7 +205,7 @@ async function fetchBalance() {
192205 const totalAmount = subscriptionData . hard_limit_usd
193206
194207 // 获取已使用量
195- response = await fetch ( urlUsage , { headers } )
208+ response = await fetch ( urlUsage , { agent : socksAgent === undefined ? httpsAgent : socksAgent , headers } )
196209 const usageData = await response . json ( )
197210 const totalUsage = usageData . total_usage / 100
198211
@@ -202,7 +215,8 @@ async function fetchBalance() {
202215
203216 return Promise . resolve ( cachedBanlance . toFixed ( 3 ) )
204217 }
205- catch {
218+ catch ( error ) {
219+ global . console . error ( error )
206220 return Promise . resolve ( '-' )
207221 }
208222}
0 commit comments