Spaces:
Paused
Paused
Update internal/handler/keys.go
Browse files- internal/handler/keys.go +22 -19
internal/handler/keys.go
CHANGED
|
@@ -71,25 +71,28 @@ func GenerateKey(n string) string {
|
|
| 71 |
}
|
| 72 |
|
| 73 |
func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {
|
|
|
|
| 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 func(name, key string) {
|
| 85 |
+
BackupKeyToSheet(name, key)
|
| 86 |
+
}(n, existingKey)
|
| 87 |
+
|
| 88 |
+
k = existingKey
|
| 89 |
+
} else {
|
| 90 |
+
k = GenerateKey(n)
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
w.Header().Set("Content-Type", "application/json")
|
| 94 |
+
resp := map[string]string{"key": k, "name": n}
|
| 95 |
+
json.NewEncoder(w).Encode(resp)
|
| 96 |
}
|
| 97 |
|
| 98 |
func HandleDeleteKey(w http.ResponseWriter, r *http.Request) {
|