修复账号没了找不到email
This commit is contained in:
@@ -108,7 +108,10 @@ func (h *AdminReadHandler) Logs(c *gin.Context) {
|
|||||||
userName = item.UserID
|
userName = item.UserID
|
||||||
}
|
}
|
||||||
var accountName any
|
var accountName any
|
||||||
if item.AccountID != "" {
|
if item.AccountEmail != "" {
|
||||||
|
// Email stamped on the row itself survives account deletion/re-import.
|
||||||
|
accountName = item.AccountEmail
|
||||||
|
} else if item.AccountID != "" {
|
||||||
if label, ok := accountByID[item.AccountID]; ok {
|
if label, ok := accountByID[item.AccountID]; ok {
|
||||||
accountName = label
|
accountName = label
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -284,7 +284,10 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) {
|
|||||||
// which upstream account (email) fulfilled their generation.
|
// which upstream account (email) fulfilled their generation.
|
||||||
var accountName, accountID any
|
var accountName, accountID any
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
if item.AccountID != "" {
|
if item.AccountEmail != "" {
|
||||||
|
// Email stamped on the row itself survives account deletion/re-import.
|
||||||
|
accountName = item.AccountEmail
|
||||||
|
} else if item.AccountID != "" {
|
||||||
if label, ok := accountByID[item.AccountID]; ok {
|
if label, ok := accountByID[item.AccountID]; ok {
|
||||||
accountName = label
|
accountName = label
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ type EventLog struct {
|
|||||||
// in-flight count (pending events per account) and lets an abandoned-event
|
// in-flight count (pending events per account) and lets an abandoned-event
|
||||||
// purge attribute the failure back to the account it was using.
|
// purge attribute the failure back to the account it was using.
|
||||||
AccountID string `gorm:"size:64;index"`
|
AccountID string `gorm:"size:64;index"`
|
||||||
|
// AccountEmail denormalizes the account's email at stamp time, so log rows
|
||||||
|
// keep showing which mailbox fulfilled the generation even after the account
|
||||||
|
// is deleted or re-imported under a different ID.
|
||||||
|
AccountEmail string `gorm:"size:255"`
|
||||||
UserID string `gorm:"size:32;index"`
|
UserID string `gorm:"size:32;index"`
|
||||||
Cost float64 `gorm:"not null;default:0"`
|
Cost float64 `gorm:"not null;default:0"`
|
||||||
// Refunded marks that this event's up-front charge has already been credited
|
// Refunded marks that this event's up-front charge has already been credited
|
||||||
|
|||||||
@@ -600,11 +600,11 @@ func (r *EventRepository) MarkRefunded(ctx context.Context, eventID string) (boo
|
|||||||
// SetAccount stamps which provider account is fulfilling an in-flight event.
|
// SetAccount stamps which provider account is fulfilling an in-flight event.
|
||||||
// Called when generation commits to a token, so the accounts view can count
|
// Called when generation commits to a token, so the accounts view can count
|
||||||
// pending events per account and an abandoned-event purge can attribute back.
|
// pending events per account and an abandoned-event purge can attribute back.
|
||||||
func (r *EventRepository) SetAccount(ctx context.Context, eventID, accountID string) error {
|
func (r *EventRepository) SetAccount(ctx context.Context, eventID, accountID, accountEmail string) error {
|
||||||
return r.db.WithContext(ctx).
|
return r.db.WithContext(ctx).
|
||||||
Model(&model.EventLog{}).
|
Model(&model.EventLog{}).
|
||||||
Where("id = ?", eventID).
|
Where("id = ?", eventID).
|
||||||
Update("account_id", accountID).Error
|
Updates(map[string]any{"account_id": accountID, "account_email": accountEmail}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// InFlightByAccount counts pending (in-flight) events grouped by account_id, for
|
// InFlightByAccount counts pending (in-flight) events grouped by account_id, for
|
||||||
|
|||||||
@@ -1457,7 +1457,7 @@ func (s *V1Service) tryAccount(ctx context.Context, eventID, pool string, token
|
|||||||
refreshOnAuth func(tokenID string) (model.TokenAccount, bool),
|
refreshOnAuth func(tokenID string) (model.TokenAccount, bool),
|
||||||
tempFailover bool,
|
tempFailover bool,
|
||||||
) ([]byte, error, bool, bool) {
|
) ([]byte, error, bool, bool) {
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
authRefreshed := false
|
authRefreshed := false
|
||||||
tempAttempts := 0
|
tempAttempts := 0
|
||||||
@@ -1711,7 +1711,7 @@ func (s *V1Service) generateRunwayVideo(ctx context.Context, eventID string, mod
|
|||||||
var data []byte
|
var data []byte
|
||||||
done, failover := func() (bool, bool) {
|
done, failover := func() (bool, bool) {
|
||||||
defer s.acctRelease(ctx, token.ID, eventID)
|
defer s.acctRelease(ctx, token.ID, eventID)
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
teamID := ""
|
teamID := ""
|
||||||
if token.Meta != nil {
|
if token.Meta != nil {
|
||||||
@@ -1851,7 +1851,7 @@ func (s *V1Service) generateCustomImage(ctx context.Context, eventID string, mod
|
|||||||
var data []byte
|
var data []byte
|
||||||
done, failover := func() (bool, bool) {
|
done, failover := func() (bool, bool) {
|
||||||
defer s.acctRelease(ctx, token.ID, eventID)
|
defer s.acctRelease(ctx, token.ID, eventID)
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
baseURL := stringValue(token.Meta["base_url"])
|
baseURL := stringValue(token.Meta["base_url"])
|
||||||
d, genErr := s.custom.GenerateImage(ctx, baseURL, token.Value, modelItem.ID, in.Prompt, size, quality, refs)
|
d, genErr := s.custom.GenerateImage(ctx, baseURL, token.Value, modelItem.ID, in.Prompt, size, quality, refs)
|
||||||
@@ -1919,7 +1919,7 @@ func (s *V1Service) generateCustomVideo(ctx context.Context, eventID string, mod
|
|||||||
var data []byte
|
var data []byte
|
||||||
done, failover := func() (bool, bool) {
|
done, failover := func() (bool, bool) {
|
||||||
defer s.acctRelease(ctx, token.ID, eventID)
|
defer s.acctRelease(ctx, token.ID, eventID)
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
baseURL := stringValue(token.Meta["base_url"])
|
baseURL := stringValue(token.Meta["base_url"])
|
||||||
d, url, genErr := s.custom.GenerateVideo(ctx, baseURL, token.Value, modelItem.ID, in.Prompt, size, durationSeconds, downloadResult)
|
d, url, genErr := s.custom.GenerateVideo(ctx, baseURL, token.Value, modelItem.ID, in.Prompt, size, durationSeconds, downloadResult)
|
||||||
@@ -2091,7 +2091,7 @@ func (s *V1Service) generateGrokVideo(ctx context.Context, eventID string, model
|
|||||||
var data []byte
|
var data []byte
|
||||||
done, failover := func() (bool, bool) {
|
done, failover := func() (bool, bool) {
|
||||||
defer s.acctRelease(ctx, token.ID, eventID)
|
defer s.acctRelease(ctx, token.ID, eventID)
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
d, meta, genErr := s.grok.GenerateVideo(ctx, token.Value, in.Prompt, aspectRatio, res, durationSeconds, frames, downloadResult)
|
d, meta, genErr := s.grok.GenerateVideo(ctx, token.Value, in.Prompt, aspectRatio, res, durationSeconds, frames, downloadResult)
|
||||||
if genErr == nil {
|
if genErr == nil {
|
||||||
@@ -2193,7 +2193,7 @@ func (s *V1Service) generateRunwayImage(ctx context.Context, eventID string, mod
|
|||||||
var data []byte
|
var data []byte
|
||||||
done, failover := func() (bool, bool) {
|
done, failover := func() (bool, bool) {
|
||||||
defer s.acctRelease(ctx, token.ID, eventID)
|
defer s.acctRelease(ctx, token.ID, eventID)
|
||||||
_ = s.events.SetAccount(ctx, eventID, token.ID)
|
_ = s.events.SetAccount(ctx, eventID, token.ID, token.AccountEmail)
|
||||||
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
_ = s.tokens.TouchLastUsed(ctx, token.ID)
|
||||||
teamID := ""
|
teamID := ""
|
||||||
if token.Meta != nil {
|
if token.Meta != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user