Add version history with rollback and per-note created/synced info
All checks were successful
ci / test (push) Successful in 3m8s
ci / release (push) Successful in 11m21s

Server (schema v2, auto-migrates): every accepted overwrite snapshots the
superseded revision into note_history (capped at 50 per note); new
GET /api/v1/notes/{id}/history endpoint; compact purges orphaned history.

Client: notes get a synced_at stamp on every confirmed server exchange;
an info footer under the editor and a Ctrl/Cmd+I panel show created/
modified/last-synced plus the revision list. Restoring a revision applies
it as a normal edit through the sync path, so rollback is non-destructive.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-25 22:20:19 +02:00
parent bd2b8e6241
commit c389bab46e
12 changed files with 563 additions and 9 deletions

View File

@@ -28,6 +28,7 @@ func (s *Server) Handler() http.Handler {
mux.HandleFunc("GET /api/v1/health", s.handleHealth)
mux.Handle("GET /api/v1/changes", s.auth(s.handleChanges))
mux.Handle("POST /api/v1/notes/batch", s.auth(s.handleBatch))
mux.Handle("GET /api/v1/notes/{id}/history", s.auth(s.handleHistory))
mux.Handle("POST /api/v1/import/simplenote", s.auth(s.handleImport))
mux.HandleFunc("OPTIONS /api/v1/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
@@ -108,6 +109,16 @@ func (s *Server) handleBatch(w http.ResponseWriter, r *http.Request) {
writeJSON(w, map[string]any{"results": results})
}
func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
revs, err := s.Store.History(r.PathValue("id"))
if err != nil {
log.Printf("history: %v", err)
jsonError(w, http.StatusInternalServerError, "internal error")
return
}
writeJSON(w, map[string]any{"revisions": revs})
}
func (s *Server) handleImport(w http.ResponseWriter, r *http.Request) {
if err := r.ParseMultipartForm(64 << 20); err != nil {
jsonError(w, http.StatusBadRequest, "bad multipart form: "+err.Error())