mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Add oplog package (internal/oplog) that records every mutating command (install, uninstall, sync, push, pull, collect, backup, restore, update, audit) as a JSONL entry with timestamp, status, duration, and args. - CLI: `skillshare log` with --audit, --tail, --clear, --project flags - API: GET/DELETE /api/log endpoints with type and limit params - Web UI: LogPage with ops/audit tabs, table view, clear and refresh - Instrumentation across 12 command handlers (CLI + server)
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"skillshare/internal/oplog"
|
|
)
|
|
|
|
func (s *Server) handleListLog(w http.ResponseWriter, r *http.Request) {
|
|
logType := r.URL.Query().Get("type")
|
|
limitStr := r.URL.Query().Get("limit")
|
|
|
|
filename := oplog.OpsFile
|
|
if logType == "audit" {
|
|
filename = oplog.AuditFile
|
|
}
|
|
|
|
limit := 100
|
|
if n, err := strconv.Atoi(limitStr); err == nil && n > 0 {
|
|
limit = n
|
|
}
|
|
|
|
entries, err := oplog.Read(s.configPath(), filename, limit)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "failed to read log: "+err.Error())
|
|
return
|
|
}
|
|
if entries == nil {
|
|
entries = []oplog.Entry{}
|
|
}
|
|
|
|
// Count total entries (read without limit)
|
|
all, _ := oplog.Read(s.configPath(), filename, 0)
|
|
total := len(all)
|
|
|
|
writeJSON(w, map[string]any{
|
|
"entries": entries,
|
|
"total": total,
|
|
})
|
|
}
|
|
|
|
func (s *Server) handleClearLog(w http.ResponseWriter, r *http.Request) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
logType := r.URL.Query().Get("type")
|
|
|
|
filename := oplog.OpsFile
|
|
if logType == "audit" {
|
|
filename = oplog.AuditFile
|
|
}
|
|
|
|
if err := oplog.Clear(s.configPath(), filename); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "failed to clear log: "+err.Error())
|
|
return
|
|
}
|
|
|
|
writeJSON(w, map[string]any{"success": true})
|
|
}
|