fix(docs): resolve docs editor live preview, multi-route editing, and disk save persistence

This commit is contained in:
2026-10-27 17:26:44 +05:30
parent dc11be2ffa
commit 7d2acbec47
7 changed files with 18273 additions and 15620 deletions
+32 -1
View File
@@ -371,7 +371,8 @@ func NewRouter(pm *ProcessManager) http.Handler {
}
var payload struct {
HTML string `json:"html"`
HTML string `json:"html"`
Data interface{} `json:"data"`
}
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil || len(payload.HTML) < 100 {
writeJSON(w, http.StatusBadRequest, map[string]interface{}{
@@ -391,9 +392,39 @@ func NewRouter(pm *ProcessManager) http.Handler {
}
_ = os.WriteFile("web/docs/FASTAPI_BACKEND_API_DOCS.html", []byte(payload.HTML), 0644)
// Save data.json and scratch/faithful_docs_data.json
var dataBytes []byte
if payload.Data != nil {
dataBytes, _ = json.MarshalIndent(payload.Data, "", " ")
} else {
// Extract from <script id="api-data" type="application/json">
startTag := `<script id="api-data" type="application/json">`
endTag := `</script>`
startIdx := strings.Index(payload.HTML, startTag)
if startIdx != -1 {
rem := payload.HTML[startIdx+len(startTag):]
endIdx := strings.Index(rem, endTag)
if endIdx != -1 {
rawJSON := rem[:endIdx]
var tmp interface{}
if err := json.Unmarshal([]byte(rawJSON), &tmp); err == nil {
dataBytes, _ = json.MarshalIndent(tmp, "", " ")
} else {
dataBytes = []byte(rawJSON)
}
}
}
}
if len(dataBytes) > 0 {
_ = os.WriteFile("web/docs/data.json", dataBytes, 0644)
_ = os.WriteFile("scratch/faithful_docs_data.json", dataBytes, 0644)
}
writeJSON(w, http.StatusOK, map[string]interface{}{
"status": "ok",
"bytes_written": len(payload.HTML),
"data_written": len(dataBytes),
})
}