Files
descrybe/apps/api/internal/httpapi/admin_settings_handlers.go
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

50 lines
1.7 KiB
Go

package httpapi
import (
"net/http"
"github.com/descrybe/descrybe-v2/apps/api/internal/feeds"
"github.com/descrybe/descrybe-v2/apps/api/internal/platformsettings"
)
// GET /api/admin/settings — platform integration config (secrets masked).
func (s *Server) handleGetAdminSettings(w http.ResponseWriter, r *http.Request) {
if s.PlatformSettings == nil {
Error(w, http.StatusServiceUnavailable, "platform settings unavailable")
return
}
view, err := s.PlatformSettings.GetPublic(r.Context())
if err != nil {
Error(w, http.StatusInternalServerError, "failed to load platform settings")
return
}
JSON(w, http.StatusOK, view)
}
// PUT /api/admin/settings — partial update; omit secrets to keep existing.
func (s *Server) handlePutAdminSettings(w http.ResponseWriter, r *http.Request) {
if s.PlatformSettings == nil {
Error(w, http.StatusServiceUnavailable, "platform settings unavailable")
return
}
var body platformsettings.UpdateInput
if err := DecodeJSON(r, &body); err != nil {
Error(w, http.StatusBadRequest, "invalid json")
return
}
view, err := s.PlatformSettings.Update(r.Context(), body)
if err != nil {
ClientOrLog(w, http.StatusBadRequest, "could not update platform settings", err, platformsettings.ClientError)
return
}
// OpenAI / ai_roles / SMTP / OAuth / Stripe / EPREL resolve at use time — no client cache to drop.
// Feed private allowlist is process-global; refresh immediately after a successful PUT.
if body.Values != nil {
if _, ok := body.Values[platformsettings.KeyFeedPrivateAllowlist]; ok {
csv, _ := s.PlatformSettings.ResolveFeedPrivateAllowlist(r.Context())
feeds.ApplyPrivateAllowlistCSV(csv)
}
}
JSON(w, http.StatusOK, view)
}