返回 DeepSeek-Reasonix
history_outline.go
根目录 / internal / serve / history_outline.go
1 package serve
2
3 import (
4 "encoding/json"
5 "net/http"
6 "reasonix/internal/session"
7 "strconv"
8 )
9
10 func (s *Server) sessionHistoryOutline(w http.ResponseWriter, r *http.Request) {
11 s.bindMu.Lock()
12 defer s.bindMu.Unlock()
13 query, ref, ok := s.canonicalSessionQuery(w, r)
14 if !ok {
15 return
16 }
17 values := r.URL.Query()
18 req := session.HistoryOutlineRequest{Generation: values.Get("generation")}
19 for key, target := range map[string]*int{"startTurn": &req.StartTurn, "limit": &req.Limit} {
20 if raw := values.Get(key); raw != "" {
21 value, err := strconv.Atoi(raw)
22 if err != nil || value < 0 {
23 http.Error(w, "invalid outline range", http.StatusBadRequest)
24 return
25 }
26 *target = value
27 }
28 }
29 if raw := values.Get("snapshotSequence"); raw != "" {
30 cut, err := strconv.ParseUint(raw, 10, 64)
31 if err != nil {
32 http.Error(w, "invalid snapshot sequence", http.StatusBadRequest)
33 return
34 }
35 req.SnapshotSequence = &cut
36 }
37 page, err := query.ReadHistoryOutline(r.Context(), ref, req)
38 if err != nil {
39 http.Error(w, err.Error(), http.StatusConflict)
40 return
41 }
42 w.Header().Set("Cache-Control", "no-store")
43 w.Header().Set("Content-Type", "application/json")
44 _ = json.NewEncoder(w).Encode(page)
45 }
46
46 lines GO