| package codex |
|
|
| import ( |
| "fmt" |
| "strings" |
| "unicode" |
| ) |
|
|
| |
| |
| |
| func CredentialFileName(email, planType, hashAccountID string, includeProviderPrefix bool) string { |
| email = strings.TrimSpace(email) |
| plan := normalizePlanTypeForFilename(planType) |
|
|
| prefix := "" |
| if includeProviderPrefix { |
| prefix = "codex" |
| } |
|
|
| if plan == "" { |
| return fmt.Sprintf("%s-%s.json", prefix, email) |
| } else if plan == "team" { |
| return fmt.Sprintf("%s-%s-%s-%s.json", prefix, hashAccountID, email, plan) |
| } |
| return fmt.Sprintf("%s-%s-%s.json", prefix, email, plan) |
| } |
|
|
| func normalizePlanTypeForFilename(planType string) string { |
| planType = strings.TrimSpace(planType) |
| if planType == "" { |
| return "" |
| } |
|
|
| parts := strings.FieldsFunc(planType, func(r rune) bool { |
| return !unicode.IsLetter(r) && !unicode.IsDigit(r) |
| }) |
| if len(parts) == 0 { |
| return "" |
| } |
|
|
| for i, part := range parts { |
| parts[i] = strings.ToLower(strings.TrimSpace(part)) |
| } |
| return strings.Join(parts, "-") |
| } |
|
|