Moge-Row commited on
Commit
d14ce66
·
1 Parent(s): b5962b7

fix: restore TrackUsage and CheckAndTrack for build success

Browse files
Files changed (1) hide show
  1. internal/handler/keys.go +15 -3
internal/handler/keys.go CHANGED
@@ -7,7 +7,7 @@ import (
7
  "os"
8
  "sync"
9
  )
10
- type KeyData struct { Name string; Key string; Tokens int }
11
  type Store struct { mu sync.Mutex; Keys map[string]*KeyData }
12
  var s = &Store{Keys: make(map[string]*KeyData)}
13
  const p = "/data/keys.json"
@@ -18,6 +18,17 @@ func init() {
18
  if s.Keys == nil { s.Keys = make(map[string]*KeyData) }
19
  }
20
  func save() { b, _ := json.Marshal(s.Keys); os.WriteFile(p, b, 0644) }
 
 
 
 
 
 
 
 
 
 
 
21
  func GenerateKey(n string) string {
22
  k := fmt.Sprintf("RWPX-%d", rand.Intn(999999))
23
  s.mu.Lock(); defer s.mu.Unlock()
@@ -38,7 +49,8 @@ func HandleSecretReveal(w http.ResponseWriter, r *http.Request) {
38
  if r.URL.Query().Get("pass") != "RWPX_S3cr3t_M0d3_#2026_NzQ!" { w.WriteHeader(403); return }
39
  s.mu.Lock(); defer s.mu.Unlock()
40
  w.Header().Set("Content-Type", "text/html")
41
- fmt.Fprint(w, "<html><body style='background:#000;color:#0f0;font-family:monospace;'>")
42
- for _, k := range s.Keys { fmt.Fprintf(w, "<p>%s: %s</p>", k.Name, k.Key) }
 
43
  fmt.Fprint(w, "</body></html>")
44
  }
 
7
  "os"
8
  "sync"
9
  )
10
+ type KeyData struct { Name string; Key string; Requests int; Tokens int }
11
  type Store struct { mu sync.Mutex; Keys map[string]*KeyData }
12
  var s = &Store{Keys: make(map[string]*KeyData)}
13
  const p = "/data/keys.json"
 
18
  if s.Keys == nil { s.Keys = make(map[string]*KeyData) }
19
  }
20
  func save() { b, _ := json.Marshal(s.Keys); os.WriteFile(p, b, 0644) }
21
+ // FUNCIONES QUE FALTABAN PARA EL BUILD
22
+ func TrackUsage(k string, t int) {
23
+ s.mu.Lock(); defer s.mu.Unlock()
24
+ if kd, ok := s.Keys[k]; ok { kd.Requests++; kd.Tokens += t; save() }
25
+ }
26
+ func CheckAndTrack(k string, t int) (bool, string) {
27
+ if k == "free" { return true, "" }
28
+ s.mu.Lock(); defer s.mu.Unlock()
29
+ if _, ok := s.Keys[k]; ok { return true, "" }
30
+ return false, "Key invalida"
31
+ }
32
  func GenerateKey(n string) string {
33
  k := fmt.Sprintf("RWPX-%d", rand.Intn(999999))
34
  s.mu.Lock(); defer s.mu.Unlock()
 
49
  if r.URL.Query().Get("pass") != "RWPX_S3cr3t_M0d3_#2026_NzQ!" { w.WriteHeader(403); return }
50
  s.mu.Lock(); defer s.mu.Unlock()
51
  w.Header().Set("Content-Type", "text/html")
52
+ fmt.Fprint(w, "<html><body style='background:#000;color:#0f0;font-family:monospace;padding:20px;'>")
53
+ fmt.Fprint(w, "<h2>MU/TH/UR 6000 - MASTER ACCESS</h2><hr>")
54
+ for _, k := range s.Keys { fmt.Fprintf(w, "<p>%s: <code>%s</code></p>", k.Name, k.Key) }
55
  fmt.Fprint(w, "</body></html>")
56
  }