Fix .gitignore swallowing internal/api handlers; commit missing session/ws files
CI / validate (push) Successful in 15s
CI / images (deploy/Dockerfile.api, api) (push) Successful in 1m32s
CI / images (deploy/Dockerfile.checker, checker) (push) Successful in 40s
CI / images (deploy/Dockerfile.web, web) (push) Successful in 23s

The bare `api` / `checker` ignore patterns matched the internal/api and cmd
directories, so handlers_sessions.go and handlers_ws.go were never committed —
CI's `go vet` failed on undefined handlers. Anchored the patterns to the repo
root (/api, /checker) and added the missing files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014TtR4PP2JM9KadaBkhPGAE
This commit is contained in:
omarandClaude Opus 4.8 committed 2026-07-02 14:50:45 +03:00
1 parent aee04924da
commit 8584040cc3
3 files changed
+158 -3

No files matched your search

+3 -3
View File
@@ -16,8 +16,8 @@ frontend/node_modules/
.DS_Store
Thumbs.db
# Build artifacts
# Build artifacts (root binaries only — anchored so they don't match internal/api etc.)
*.exe
api
checker
/api
/checker
frontend/*.tsbuildinfo
+86
View File
@@ -0,0 +1,86 @@
package api
import (
"net/http"
"git.qomar.pw/omar/zhguchiy_perchik/internal/db"
)
// handleListSessions returns the check-session history (newest first).
func (s *Server) handleListSessions(w http.ResponseWriter, r *http.Request) {
sessions, err := s.db.RecentSessions(r.Context(), 200)
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
if sessions == nil {
sessions = []db.Session{}
}
writeJSON(w, http.StatusOK, map[string]any{"items": sessions})
}
// handleGetSession returns one session plus its per-protocol / per-source /
// per-country breakdowns and latency/speed aggregates.
func (s *Server) handleGetSession(w http.ResponseWriter, r *http.Request) {
id, ok := pathID(r)
if !ok {
writeErr(w, http.StatusBadRequest, "bad id")
return
}
ctx := r.Context()
sess, err := s.db.GetSessionByID(ctx, id)
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
if sess == nil {
writeErr(w, http.StatusNotFound, "not found")
return
}
resp := map[string]any{"session": sess}
if v, err := s.db.ProtocolStats(ctx, id); err == nil {
resp["protocols"] = v
}
if v, err := s.db.SourceStats(ctx, id); err == nil {
resp["sources"] = v
}
if v, err := s.db.CountryStats(ctx, id, 30); err == nil {
resp["countries"] = v
}
if avg, median, err := s.db.LatencyAvgMedian(ctx, id); err == nil {
resp["latency_avg"] = avg
resp["latency_median"] = median
}
if avg, median, err := s.db.SpeedAvgMedian(ctx, id); err == nil {
resp["speed_avg"] = avg
resp["speed_median"] = median
}
writeJSON(w, http.StatusOK, resp)
}
// handleSessionProxies lists the proxies that were valid in a given session
// (works for any historical session, not just the current one).
func (s *Server) handleSessionProxies(w http.ResponseWriter, r *http.Request) {
id, ok := pathID(r)
if !ok {
writeErr(w, http.StatusBadRequest, "bad id")
return
}
ctx := r.Context()
f := parseProxyFilter(r)
total, err := s.db.CountSessionProxies(ctx, id, f)
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
items, err := s.db.ListSessionProxies(ctx, id, f, true)
if err != nil {
writeErr(w, http.StatusInternalServerError, err.Error())
return
}
if items == nil {
items = []db.SessionProxy{}
}
writeJSON(w, http.StatusOK, map[string]any{"items": items, "total": total})
}
+69
View File
@@ -0,0 +1,69 @@
package api
import (
"net/http"
"time"
"github.com/gorilla/websocket"
)
var wsUpgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
// Same-origin in production (nginx) and dev (vite proxy); the endpoint is
// authenticated, so we accept the upgrade regardless of Origin.
CheckOrigin: func(*http.Request) bool { return true },
}
// handleWSStatus streams the checker status (busy + running session progress +
// current session) to the client roughly once a second, giving the panel a live
// feed without aggressive polling. The connection closes when the client leaves
// or the request context is cancelled.
func (s *Server) handleWSStatus(w http.ResponseWriter, r *http.Request) {
conn, err := wsUpgrader.Upgrade(w, r, nil)
if err != nil {
return // Upgrade already wrote an error response.
}
defer conn.Close()
ctx := r.Context()
// Reader pump: detect client close / respond to control frames.
go func() {
for {
if _, _, err := conn.ReadMessage(); err != nil {
conn.Close()
return
}
}
}()
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
send := func() bool {
running, _ := s.db.GetRunningSession(ctx)
current, _ := s.db.GetCurrentSession(ctx)
payload := map[string]any{
"busy": running != nil,
"running": running,
"current": current,
"ts": time.Now().UnixMilli(),
}
_ = conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
return conn.WriteJSON(payload) == nil
}
if !send() {
return
}
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
if !send() {
return
}
}
}
}