package api import ( "net/http" "git.golem15.com/golem15/sm-journal-plugin/classes" "git.golem15.com/golem15/summercms/modules/backpack" "git.golem15.com/golem15/summercms/modules/wire" ) // FixHeadings is POST /_journal/api/v1/fix-headings {dry_run}: the // journal:fix-headings conversion of stored H1 headings (posts in every // locale and category pillar text), for golem15.journal.manage_settings. It // is a dry run unless dry_run is false, and answers {posts, categories, // headings, dry_run}. While the H1 setting is off it refuses with 409 and // the refusal phrase. MCP journal_fix_headings. func FixHeadings(app *backpack.App) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { r, pr, ok := requireBackendPrincipal(app, w, r) if !ok || !requireManageSettings(w, pr) { return } db, err := gdb(app) if err != nil { writeAPIError(w, http.StatusInternalServerError, "Internal server error") return } body, err := readJSONObject(r) if err != nil { writeAPIError(w, http.StatusBadRequest, errValidationFailed) return } dry := true if v, has := body["dry_run"]; has && v != nil { dry = asBool(v) } if !classes.EffectiveH1ToH2(r.Context(), db, appConfig(app)) { writeAPIError(w, http.StatusConflict, classes.H1ConversionOffText) return } res, err := classes.FixStoredHeadings(r.Context(), app, db, !dry) if err != nil { writeAPIError(w, http.StatusInternalServerError, "Internal server error") return } wire.WriteJSON(w, http.StatusOK, map[string]any{ "posts": res.Posts, "categories": res.Categories, "headings": res.Headings, "dry_run": dry, }) } }