Changeset 0.8.0.1 (#43)

This commit is contained in:
2026-02-22 00:39:45 +00:00
parent 8925e8dcbf
commit 1adef94617
14 changed files with 902 additions and 16 deletions

View File

@@ -435,6 +435,7 @@ type adminGlobalConfigResponse struct {
Endpoint string `json:"endpoint"`
ModelDefault *string `json:"model_default"`
IsActive bool `json:"is_active"`
IsPrivate bool `json:"is_private"`
HasKey bool `json:"has_key"`
CreatedAt string `json:"created_at"`
}
@@ -442,6 +443,7 @@ type adminGlobalConfigResponse struct {
func (h *AdminHandler) ListGlobalConfigs(c *gin.Context) {
rows, err := database.DB.Query(`
SELECT id, name, provider, endpoint, model_default, is_active,
COALESCE(is_private, false),
(api_key_encrypted IS NOT NULL AND api_key_encrypted != '') as has_key,
created_at
FROM api_configs
@@ -459,7 +461,7 @@ func (h *AdminHandler) ListGlobalConfigs(c *gin.Context) {
var cfg adminGlobalConfigResponse
if err := rows.Scan(
&cfg.ID, &cfg.Name, &cfg.Provider, &cfg.Endpoint,
&cfg.ModelDefault, &cfg.IsActive, &cfg.HasKey, &cfg.CreatedAt,
&cfg.ModelDefault, &cfg.IsActive, &cfg.IsPrivate, &cfg.HasKey, &cfg.CreatedAt,
); err != nil {
continue
}
@@ -478,10 +480,10 @@ func (h *AdminHandler) CreateGlobalConfig(c *gin.Context) {
var id string
err := database.DB.QueryRow(`
INSERT INTO api_configs (name, provider, endpoint, api_key_encrypted, model_default, user_id, is_global)
VALUES ($1, $2, $3, $4, $5, NULL, true)
INSERT INTO api_configs (name, provider, endpoint, api_key_encrypted, model_default, user_id, is_global, is_private)
VALUES ($1, $2, $3, $4, $5, NULL, true, $6)
RETURNING id
`, req.Name, req.Provider, req.Endpoint, req.APIKey, req.ModelDefault).Scan(&id)
`, req.Name, req.Provider, req.Endpoint, req.APIKey, req.ModelDefault, req.IsPrivate).Scan(&id)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed to create config"})
return
@@ -498,6 +500,7 @@ func (h *AdminHandler) UpdateGlobalConfig(c *gin.Context) {
Endpoint *string `json:"endpoint"`
APIKey *string `json:"api_key"`
ModelDefault *string `json:"model_default"`
IsPrivate *bool `json:"is_private"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
@@ -517,6 +520,7 @@ func (h *AdminHandler) UpdateGlobalConfig(c *gin.Context) {
if req.Endpoint != nil { add("endpoint", *req.Endpoint) }
if req.APIKey != nil && *req.APIKey != "" { add("api_key_encrypted", *req.APIKey) }
if req.ModelDefault != nil { add("model_default", *req.ModelDefault) }
if req.IsPrivate != nil { add("is_private", *req.IsPrivate) }
if len(sets) == 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "no fields to update"})