fix: show websearch API key visibility/copy buttons for saved providers

The buttons were hidden because v-if only checked provider.api_key,
which is always empty for saved providers (backend sanitizes it).
Now also checks api_key_configured. Copy button is disabled when
no actual key is available (only configured placeholder shown).
This commit is contained in:
erio
2026-04-14 07:22:22 +08:00
parent b402c367d3
commit 9e0d12d3b0
4 changed files with 39 additions and 10 deletions

View File

@@ -1 +1 @@
0.1.110.51
0.1.112.3

View File

@@ -1939,7 +1939,7 @@ func (h *SettingHandler) GetWebSearchEmulationConfig(c *gin.Context) {
response.ErrorFrom(c, err)
return
}
response.Success(c, service.SanitizeWebSearchConfig(c.Request.Context(), cfg))
response.Success(c, service.PopulateWebSearchUsage(c.Request.Context(), cfg))
}
// UpdateWebSearchEmulationConfig 更新 Web Search 模拟配置

View File

@@ -277,6 +277,28 @@ func TestWebSearch(ctx context.Context, query string) (*WebSearchTestResult, err
}, nil
}
// PopulateWebSearchUsage returns a copy with quota usage populated from Redis (api_key kept as-is).
func PopulateWebSearchUsage(ctx context.Context, cfg *WebSearchEmulationConfig) *WebSearchEmulationConfig {
if cfg == nil {
return nil
}
out := *cfg
out.Providers = make([]WebSearchProviderConfig, len(cfg.Providers))
mgr := getWebSearchManager()
for i, p := range cfg.Providers {
out.Providers[i] = p
out.Providers[i].APIKeyConfigured = p.APIKey != ""
if mgr != nil {
used, _ := mgr.GetUsage(ctx, p.Type)
out.Providers[i].QuotaUsed = used
}
}
return &out
}
// SanitizeWebSearchConfig returns a copy with api_key fields masked and quota usage populated.
func SanitizeWebSearchConfig(ctx context.Context, cfg *WebSearchEmulationConfig) *WebSearchEmulationConfig {
if cfg == nil {