mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(auth): replace sanitizeAntigravityFileName with antigravity.CredentialFileName
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/antigravity"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/claude"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/claude"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/codex"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/codex"
|
||||||
geminiAuth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/gemini"
|
geminiAuth "github.com/router-for-me/CLIProxyAPI/v6/internal/auth/gemini"
|
||||||
@@ -232,14 +233,6 @@ func stopForwarderInstance(port int, forwarder *callbackForwarder) {
|
|||||||
log.Infof("callback forwarder on port %d stopped", port)
|
log.Infof("callback forwarder on port %d stopped", port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanitizeAntigravityFileName(email string) string {
|
|
||||||
if strings.TrimSpace(email) == "" {
|
|
||||||
return "antigravity.json"
|
|
||||||
}
|
|
||||||
replacer := strings.NewReplacer("@", "_", ".", "_")
|
|
||||||
return fmt.Sprintf("antigravity-%s.json", replacer.Replace(email))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) managementCallbackURL(path string) (string, error) {
|
func (h *Handler) managementCallbackURL(path string) (string, error) {
|
||||||
if h == nil || h.cfg == nil || h.cfg.Port <= 0 {
|
if h == nil || h.cfg == nil || h.cfg.Port <= 0 {
|
||||||
return "", fmt.Errorf("server port is not configured")
|
return "", fmt.Errorf("server port is not configured")
|
||||||
@@ -1715,7 +1708,7 @@ func (h *Handler) RequestAntigravityToken(c *gin.Context) {
|
|||||||
metadata["project_id"] = projectID
|
metadata["project_id"] = projectID
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := sanitizeAntigravityFileName(email)
|
fileName := antigravity.CredentialFileName(email)
|
||||||
label := strings.TrimSpace(email)
|
label := strings.TrimSpace(email)
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = "antigravity"
|
label = "antigravity"
|
||||||
|
|||||||
16
internal/auth/antigravity/filename.go
Normal file
16
internal/auth/antigravity/filename.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package antigravity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CredentialFileName returns the filename used to persist Antigravity credentials.
|
||||||
|
// It uses the email as a suffix to disambiguate accounts.
|
||||||
|
func CredentialFileName(email string) string {
|
||||||
|
email = strings.TrimSpace(email)
|
||||||
|
if email == "" {
|
||||||
|
return "antigravity.json"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("antigravity-%s.json", email)
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/auth/antigravity"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/browser"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/browser"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/misc"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/misc"
|
||||||
@@ -204,7 +205,7 @@ waitForCallback:
|
|||||||
metadata["project_id"] = projectID
|
metadata["project_id"] = projectID
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := sanitizeAntigravityFileName(email)
|
fileName := antigravity.CredentialFileName(email)
|
||||||
label := email
|
label := email
|
||||||
if label == "" {
|
if label == "" {
|
||||||
label = "antigravity"
|
label = "antigravity"
|
||||||
@@ -354,14 +355,6 @@ func buildAntigravityAuthURL(redirectURI, state string) string {
|
|||||||
return "https://accounts.google.com/o/oauth2/v2/auth?" + params.Encode()
|
return "https://accounts.google.com/o/oauth2/v2/auth?" + params.Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanitizeAntigravityFileName(email string) string {
|
|
||||||
if strings.TrimSpace(email) == "" {
|
|
||||||
return "antigravity.json"
|
|
||||||
}
|
|
||||||
replacer := strings.NewReplacer("@", "_", ".", "_")
|
|
||||||
return fmt.Sprintf("antigravity-%s.json", replacer.Replace(email))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Antigravity API constants for project discovery
|
// Antigravity API constants for project discovery
|
||||||
const (
|
const (
|
||||||
antigravityAPIEndpoint = "https://cloudcode-pa.googleapis.com"
|
antigravityAPIEndpoint = "https://cloudcode-pa.googleapis.com"
|
||||||
|
|||||||
Reference in New Issue
Block a user