MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / updateAllChannelsBalance

Function updateAllChannelsBalance

controller/channel-billing.go:441–469  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

439}
440
441func updateAllChannelsBalance() error {
442 channels, err := model.GetAllChannels(0, 0, true, false)
443 if err != nil {
444 return err
445 }
446 for _, channel := range channels {
447 if channel.Status != common.ChannelStatusEnabled {
448 continue
449 }
450 if channel.ChannelInfo.IsMultiKey {
451 continue // skip multi-key channels
452 }
453 // TODO: support Azure
454 //if channel.Type != common.ChannelTypeOpenAI && channel.Type != common.ChannelTypeCustom {
455 // continue
456 //}
457 balance, err := updateChannelBalance(channel)
458 if err != nil {
459 continue
460 } else {
461 // err is nil & balance <= 0 means quota is used up
462 if balance <= 0 {
463 service.DisableChannel(*types.NewChannelError(channel.Id, channel.Type, channel.Name, channel.ChannelInfo.IsMultiKey, "", channel.GetAutoBan()), "余额不足")
464 }
465 }
466 time.Sleep(common.RequestInterval)
467 }
468 return nil
469}
470
471func UpdateAllChannelsBalance(c *gin.Context) {
472 // TODO: make it async

Callers 2

UpdateAllChannelsBalanceFunction · 0.70

Calls 5

GetAllChannelsFunction · 0.92
DisableChannelFunction · 0.92
NewChannelErrorFunction · 0.92
GetAutoBanMethod · 0.80
updateChannelBalanceFunction · 0.70

Tested by

no test coverage detected