fix(Antigravity): 配额刷新时自动补充缺失的 project_id

旧账户可能没有 project_id,在刷新配额时自动生成并保存。
This commit is contained in:
song
2025-12-30 23:58:03 +08:00
parent fa48cf27eb
commit 0a4e0edc85

View File

@@ -145,16 +145,25 @@ func (r *AntigravityQuotaRefresher) refreshAccountQuota(ctx context.Context, acc
client := antigravity.NewClient(proxyURL)
// 获取账户类型tier
// 获取账户类型tier和 project_id
loadResp, _ := client.LoadCodeAssist(ctx, accessToken)
if loadResp != nil {
r.updateAccountTier(account, loadResp)
// 尝试从 API 获取 project_id
if projectID == "" && loadResp.CloudAICompanionProject != "" {
projectID = loadResp.CloudAICompanionProject
account.Credentials["project_id"] = projectID
}
}
// 调用 API 获取配额(需要 projectID
// 如果仍然没有 project_id随机生成一个并保存
if projectID == "" {
return r.accountRepo.Update(ctx, account) // 没有 projectID只更新 tier
projectID = antigravity.GenerateMockProjectID()
account.Credentials["project_id"] = projectID
log.Printf("[AntigravityQuotaRefresher] 为账户 %d 生成随机 project_id: %s", account.ID, projectID)
}
// 调用 API 获取配额
modelsResp, err := client.FetchAvailableModels(ctx, accessToken, projectID)
if err != nil {
return err