feat(sources): enforce supported source allowlist

Assign stable keys to the three supported sources, preserve excluded historical rows, and expose history read-only in admin. Add migration, coverage, and responsive browser spec.

Refs #13

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 00:11:26 +01:00
parent 4459a81206
commit ac17d27f51
26 changed files with 924 additions and 61 deletions

View File

@ -233,7 +233,16 @@ func (h *Handler) ListSources(c *gin.Context) {
httputil.InternalError(c, err)
return
}
httputil.OK(c, sources)
type sourceResponse struct {
models.Source
Supported bool `json:"supported"`
Operational bool `json:"operational"`
}
result := make([]sourceResponse, 0, len(sources))
for _, source := range sources {
result = append(result, sourceResponse{Source: source, Supported: source.Supported(), Operational: source.Operational()})
}
httputil.OK(c, result)
}
type updateSourceRequest struct {
@ -248,6 +257,14 @@ func (h *Handler) UpdateSource(c *gin.Context) {
return
}
if err := h.repo.UpdateSource(c.Param("id"), req.Enabled, req.ArticleLimit); err != nil {
if errors.Is(err, models.ErrSourceNotSupported) {
c.JSON(http.StatusConflict, gin.H{"error": "source_not_supported"})
return
}
if errors.Is(err, sql.ErrNoRows) {
httputil.NotFound(c)
return
}
httputil.InternalError(c, err)
return
}