refactor: remove LocaleSwitcher component and update locale handling
- Removed LocaleSwitcher from NavUser, SiteHeader, and WorkbenchHeader components. - Updated tests to reflect the removal of LocaleSwitcher. - Changed default locale from "en-US" to "zh-CN" in i18n configuration. - Refactored locale resolution logic to read configured locale without relying on browser language detection. - Updated AgentDesk SDK to support language configuration from public API. - Cleaned up unused auth options fetching in the auth API.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"agent-desk/internal/ai/rag/vectordb"
|
||||
"agent-desk/internal/oidcclient"
|
||||
"agent-desk/internal/pkg/config"
|
||||
"agent-desk/internal/pkg/i18nx"
|
||||
"agent-desk/internal/pkg/logx"
|
||||
"agent-desk/internal/services/cronx"
|
||||
"agent-desk/internal/wxwork"
|
||||
@@ -20,6 +21,7 @@ func Init(configPath string) error {
|
||||
return err
|
||||
}
|
||||
config.SetCurrent(cfg)
|
||||
i18nx.SetDefaultLocale(cfg.LanguageOrDefault())
|
||||
|
||||
logx.Init(logx.Config{
|
||||
Level: cfg.Logger.Level,
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
func registerApiAuthRoutes(group *gin.RouterGroup) {
|
||||
group.POST("/login", api.Login)
|
||||
group.POST("/logout", api.Logout)
|
||||
group.GET("/options", api.AuthOptions)
|
||||
group.GET("/profile", api.Profile)
|
||||
group.GET("/wxwork_callback", api.WxWorkCallback)
|
||||
group.POST("/wxwork_exchange", api.WxWorkExchange)
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
func NewServer() (*gin.Engine, error) {
|
||||
cfg := config.Current()
|
||||
i18nx.SetDefaultLocale(cfg.LanguageOrDefault())
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
printBanner()
|
||||
@@ -156,6 +157,7 @@ func addRouter(app *gin.Engine) {
|
||||
|
||||
apiGroup := app.Group("/api")
|
||||
apiGroup.GET("/health", api.Health)
|
||||
apiGroup.GET("/config", api.PublicConfig)
|
||||
registerApiAuthRoutes(apiGroup.Group("/auth"))
|
||||
registerApiChannelRoutes(apiGroup.Group("/channel"))
|
||||
registerApiCustomerRoutes(apiGroup.Group("/customer"))
|
||||
|
||||
@@ -32,6 +32,7 @@ func TestNewServerRegistersGinRoutes(t *testing.T) {
|
||||
|
||||
expected := []string{
|
||||
http.MethodPost + " /api/auth/login",
|
||||
http.MethodGet + " /api/config",
|
||||
http.MethodGet + " /api/health",
|
||||
http.MethodGet + " /api/auth/oidc_login",
|
||||
http.MethodGet + " /api/auth/oidc_callback",
|
||||
@@ -93,8 +94,9 @@ func TestNewServerHealthEndpointIsPublic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
func TestNewServerExposesPublicConfig(t *testing.T) {
|
||||
config.SetCurrent(&config.Config{
|
||||
Language: "zh-CN",
|
||||
Storage: config.StorageConfig{
|
||||
Local: config.LocalStorageConfig{
|
||||
Root: "storage",
|
||||
@@ -116,7 +118,7 @@ func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
app.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/auth/options", nil))
|
||||
app.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/config", nil))
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d want %d", rec.Code, http.StatusOK)
|
||||
@@ -125,8 +127,9 @@ func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
var body struct {
|
||||
Success bool `json:"success"`
|
||||
Data struct {
|
||||
WxWorkEnabled bool `json:"wxworkEnabled"`
|
||||
OIDCEnabled bool `json:"oidcEnabled"`
|
||||
Language string `json:"language"`
|
||||
WxWorkEnabled bool `json:"wxworkEnabled"`
|
||||
OIDCEnabled bool `json:"oidcEnabled"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
@@ -135,6 +138,9 @@ func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
if !body.Success {
|
||||
t.Fatalf("success=false, body=%s", rec.Body.String())
|
||||
}
|
||||
if body.Data.Language != "zh-CN" {
|
||||
t.Fatalf("language=%q want zh-CN", body.Data.Language)
|
||||
}
|
||||
if !body.Data.WxWorkEnabled {
|
||||
t.Fatalf("wxworkEnabled=false want true")
|
||||
}
|
||||
@@ -146,6 +152,29 @@ func TestNewServerExposesPublicAuthOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerDoesNotExposeLegacyAuthOptions(t *testing.T) {
|
||||
config.SetCurrent(&config.Config{
|
||||
Storage: config.StorageConfig{
|
||||
Local: config.LocalStorageConfig{
|
||||
Root: "storage",
|
||||
BaseURL: "/storage",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
app, err := NewServer()
|
||||
if err != nil {
|
||||
t.Fatalf("NewServer() error = %v", err)
|
||||
}
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
app.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/auth/options", nil))
|
||||
|
||||
if rec.Code != http.StatusNotFound {
|
||||
t.Fatalf("status=%d want %d, body=%s", rec.Code, http.StatusNotFound, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewServerSeparatesAPIStaticAndSPA(t *testing.T) {
|
||||
config.SetCurrent(&config.Config{
|
||||
Storage: config.StorageConfig{
|
||||
|
||||
Reference in New Issue
Block a user