Spaces:
Paused
Paused
add delete key endpoint
Browse files- internal/handler/keys.go +10 -0
- main.go +1 -0
internal/handler/keys.go
CHANGED
|
@@ -88,6 +88,16 @@ func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
|
| 88 |
json.NewEncoder(w).Encode(resp)
|
| 89 |
}
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 92 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 93 |
w.Header().Set("Content-Type", "application/json")
|
|
|
|
| 88 |
json.NewEncoder(w).Encode(resp)
|
| 89 |
}
|
| 90 |
|
| 91 |
+
func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {
|
| 92 |
+
if r.URL.Query().Get("token") != "CCCP_IS2_1944_STALIN" { w.WriteHeader(403); return }
|
| 93 |
+
k := r.FormValue("key")
|
| 94 |
+
if k == "" { http.Error(w, "key required", 400); return }
|
| 95 |
+
s.mu.Lock(); defer s.mu.Unlock()
|
| 96 |
+
delete(s.Keys, k)
|
| 97 |
+
save()
|
| 98 |
+
w.Write([]byte("OK"))
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
| 102 |
s.mu.Lock(); defer s.mu.Unlock()
|
| 103 |
w.Header().Set("Content-Type", "application/json")
|
main.go
CHANGED
|
@@ -17,6 +17,7 @@ func main() {
|
|
| 17 |
http.HandleFunc("/", handler.HandleIndex)
|
| 18 |
http.HandleFunc("/genkey", handler.HandleGenKey)
|
| 19 |
http.HandleFunc("/stats", handler.HandleStats)
|
|
|
|
| 20 |
http.HandleFunc("/internal-debug-v1", handler.HandleSecretReveal)
|
| 21 |
http.HandleFunc("/v1/models", handler.HandleModels)
|
| 22 |
http.HandleFunc("/v1/chat/completions", handler.HandleChatCompletions)
|
|
|
|
| 17 |
http.HandleFunc("/", handler.HandleIndex)
|
| 18 |
http.HandleFunc("/genkey", handler.HandleGenKey)
|
| 19 |
http.HandleFunc("/stats", handler.HandleStats)
|
| 20 |
+
http.HandleFunc("/deletekey", handler.HandleDeleteKey)
|
| 21 |
http.HandleFunc("/internal-debug-v1", handler.HandleSecretReveal)
|
| 22 |
http.HandleFunc("/v1/models", handler.HandleModels)
|
| 23 |
http.HandleFunc("/v1/chat/completions", handler.HandleChatCompletions)
|