Spaces:
Paused
Paused
Update internal/handler/keys.go
Browse files- internal/handler/keys.go +13 -12
internal/handler/keys.go
CHANGED
|
@@ -63,29 +63,30 @@ func GenerateKey(n string) string {
|
|
| 63 |
k := "RWPX-" + string(b)
|
| 64 |
|
| 65 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 66 |
-
|
| 67 |
s.Keys[n+":"+k] = &KeyData{Name: n, Key: k}
|
| 68 |
-
|
| 69 |
go BackupKeyToSheet(n, k)
|
| 70 |
save()
|
| 71 |
return k
|
| 72 |
}
|
|
|
|
| 73 |
func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
| 74 |
n := r.FormValue("name")
|
| 75 |
if n == "" { n = "User" }
|
| 76 |
existingKey := r.FormValue("key")
|
| 77 |
var k string
|
|
|
|
| 78 |
if existingKey != "" {
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
}
|
| 84 |
go BackupKeyToSheet(n, existingKey)
|
| 85 |
k = existingKey
|
| 86 |
} else {
|
| 87 |
k = GenerateKey(n)
|
| 88 |
}
|
|
|
|
| 89 |
w.Header().Set("Content-Type", "application/json")
|
| 90 |
resp := map[string]string{"key": k, "name": n}
|
| 91 |
json.NewEncoder(w).Encode(resp)
|
|
@@ -105,7 +106,8 @@ func HandleStats(w http.ResponseWriter, r *http.Request) {
|
|
| 105 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 106 |
w.Header().Set("Content-Type", "application/json")
|
| 107 |
public := make(map[string]interface{})
|
| 108 |
-
for
|
|
|
|
| 109 |
public[v.Name] = map[string]interface{}{"name": v.Name, "requests": v.Requests}
|
| 110 |
}
|
| 111 |
json.NewEncoder(w).Encode(map[string]interface{}{"keys": public})
|
|
@@ -116,8 +118,7 @@ func HandleSecretReveal(w http.ResponseWriter, r *http.Request) {
|
|
| 116 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 117 |
w.Header().Set("Content-Type", "text/html")
|
| 118 |
w.Write([]byte("<body style='background:#000;color:#0f0;font-family:monospace;'>"))
|
| 119 |
-
for
|
| 120 |
-
w.Write([]byte("<p>" +
|
| 121 |
}
|
| 122 |
-
w.Write([]byte("</body>"))
|
| 123 |
-
}
|
|
|
|
| 63 |
k := "RWPX-" + string(b)
|
| 64 |
|
| 65 |
s.mu.Lock(); defer s.mu.Unlock()
|
|
|
|
| 66 |
s.Keys[n+":"+k] = &KeyData{Name: n, Key: k}
|
| 67 |
+
|
| 68 |
go BackupKeyToSheet(n, k)
|
| 69 |
save()
|
| 70 |
return k
|
| 71 |
}
|
| 72 |
+
|
| 73 |
func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
| 74 |
n := r.FormValue("name")
|
| 75 |
if n == "" { n = "User" }
|
| 76 |
existingKey := r.FormValue("key")
|
| 77 |
var k string
|
| 78 |
+
|
| 79 |
if existingKey != "" {
|
| 80 |
+
s.mu.Lock()
|
| 81 |
+
s.Keys[n+":"+existingKey] = &KeyData{Name: n, Key: existingKey}
|
| 82 |
+
save()
|
| 83 |
+
s.mu.Unlock()
|
|
|
|
| 84 |
go BackupKeyToSheet(n, existingKey)
|
| 85 |
k = existingKey
|
| 86 |
} else {
|
| 87 |
k = GenerateKey(n)
|
| 88 |
}
|
| 89 |
+
|
| 90 |
w.Header().Set("Content-Type", "application/json")
|
| 91 |
resp := map[string]string{"key": k, "name": n}
|
| 92 |
json.NewEncoder(w).Encode(resp)
|
|
|
|
| 106 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 107 |
w.Header().Set("Content-Type", "application/json")
|
| 108 |
public := make(map[string]interface{})
|
| 109 |
+
for k, v := range s.Keys {
|
| 110 |
+
// k aquí es "NOMBRE:KEY", usamos v.Name para las estadísticas públicas
|
| 111 |
public[v.Name] = map[string]interface{}{"name": v.Name, "requests": v.Requests}
|
| 112 |
}
|
| 113 |
json.NewEncoder(w).Encode(map[string]interface{}{"keys": public})
|
|
|
|
| 118 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 119 |
w.Header().Set("Content-Type", "text/html")
|
| 120 |
w.Write([]byte("<body style='background:#000;color:#0f0;font-family:monospace;'>"))
|
| 121 |
+
for compositeKey, k := range s.Keys {
|
| 122 |
+
w.Write([]byte("<p>" + compositeKey + "</p>"))
|
| 123 |
}
|
| 124 |
+
w.Write([]byte("</body>"))
|
|
|