fix: Bybit shared HTTP client, auth token bugs, consistent safe.ReadAllLimited

- Bybit: replace http.Get/http.DefaultClient with shared bybitHTTPClient (30s timeout, connection pooling)
- Frontend: fix resetPassword missing auth token (endpoint now requires auth)
- Frontend: fix SettingsPage using wrong localStorage key ('token' → 'auth_token')
- Agent: migrate remaining io.ReadAll(io.LimitReader()) to safe.ReadAllLimited for consistency
- Remove unused 'io' imports from brain.go and sentinel.go
This commit is contained in:
shinchan-zhai
2026-03-23 11:28:54 +08:00
parent b9c9f05603
commit bb459d6f9f
8 changed files with 21 additions and 12 deletions

View File

@@ -3,7 +3,6 @@ package agent
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"nofx/safe"
@@ -87,7 +86,7 @@ func (b *Brain) scanNews(seen map[string]bool) {
b.logger.Debug("news API non-200", "status", resp.StatusCode)
return
}
body, err := io.ReadAll(io.LimitReader(resp.Body, 1024*1024)) // 1MB limit
body, err := safe.ReadAllLimited(resp.Body, 1024*1024) // 1MB limit
if err != nil { return }
var result struct {
@@ -167,7 +166,7 @@ func (b *Brain) sendBrief(hour int) {
for _, sym := range []string{"BTCUSDT", "ETHUSDT"} {
resp, err := b.http.Get(fmt.Sprintf("https://fapi.binance.com/fapi/v1/ticker/24hr?symbol=%s", sym))
if err != nil { continue }
body, readErr := io.ReadAll(io.LimitReader(resp.Body, 64*1024)) // 64KB limit
body, readErr := safe.ReadAllLimited(resp.Body, 64*1024) // 64KB limit
statusOK := resp.StatusCode == http.StatusOK
resp.Body.Close()
if readErr != nil || !statusOK { continue }

View File

@@ -3,7 +3,6 @@ package agent
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"math"
"net/http"
@@ -120,7 +119,7 @@ func (s *Sentinel) check(symbol string) {
s.logger.Debug("sentinel ticker non-200", "symbol", symbol, "status", resp.StatusCode)
return
}
body, err := io.ReadAll(io.LimitReader(resp.Body, 256*1024)) // 256KB limit
body, err := safe.ReadAllLimited(resp.Body, 256*1024) // 256KB limit
if err != nil { return }
var t map[string]interface{}
if err := json.Unmarshal(body, &t); err != nil { return }