- gofmt: 修复 admin_service/antigravity_oauth_service/token_refresh_service 格式 - staticcheck S1009: 移除 SetUserSettingsResponse.IsSuccess 中冗余的 nil 检查 - unused: 将仅测试使用的 applyAntigravitySubscriptionResult 移至测试文件 Made-with: Cursor
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package service
|
||
|
||
import (
|
||
"strings"
|
||
|
||
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
|
||
)
|
||
|
||
const antigravitySubscriptionAbnormal = "abnormal"
|
||
|
||
// AntigravitySubscriptionResult 表示订阅检测后的规范化结果。
|
||
type AntigravitySubscriptionResult struct {
|
||
PlanType string
|
||
SubscriptionStatus string
|
||
SubscriptionError string
|
||
}
|
||
|
||
// NormalizeAntigravitySubscription 从 LoadCodeAssistResponse 提取 plan_type + 异常状态。
|
||
// 使用 GetTier()(返回 tier ID)+ TierIDToPlanType 映射。
|
||
func NormalizeAntigravitySubscription(resp *antigravity.LoadCodeAssistResponse) AntigravitySubscriptionResult {
|
||
if resp == nil {
|
||
return AntigravitySubscriptionResult{PlanType: "Free"}
|
||
}
|
||
if len(resp.IneligibleTiers) > 0 {
|
||
result := AntigravitySubscriptionResult{
|
||
PlanType: "Abnormal",
|
||
SubscriptionStatus: antigravitySubscriptionAbnormal,
|
||
}
|
||
if resp.IneligibleTiers[0] != nil {
|
||
result.SubscriptionError = strings.TrimSpace(resp.IneligibleTiers[0].ReasonMessage)
|
||
}
|
||
return result
|
||
}
|
||
tierID := resp.GetTier()
|
||
return AntigravitySubscriptionResult{
|
||
PlanType: antigravity.TierIDToPlanType(tierID),
|
||
}
|
||
}
|