Spaces:
Paused
Paused
genkey accepts existing key
Browse files- internal/handler/keys.go +12 -1
internal/handler/keys.go
CHANGED
|
@@ -71,7 +71,18 @@ func GenerateKey(n string) string {
|
|
| 71 |
func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
| 72 |
n := r.FormValue("name")
|
| 73 |
if n == "" { n = "User" }
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
w.Header().Set("Content-Type", "application/json")
|
| 76 |
resp := map[string]string{"key": k, "name": n}
|
| 77 |
json.NewEncoder(w).Encode(resp)
|
|
|
|
| 71 |
func HandleGenKey(w http.ResponseWriter, r *http.Request) {
|
| 72 |
n := r.FormValue("name")
|
| 73 |
if n == "" { n = "User" }
|
| 74 |
+
existingKey := r.FormValue("key")
|
| 75 |
+
var k string
|
| 76 |
+
if existingKey != "" {
|
| 77 |
+
s.mu.Lock()
|
| 78 |
+
s.Keys[existingKey] = &KeyData{Name: n, Key: existingKey}
|
| 79 |
+
save()
|
| 80 |
+
s.mu.Unlock()
|
| 81 |
+
go BackupKeyToSheet(n, existingKey)
|
| 82 |
+
k = existingKey
|
| 83 |
+
} else {
|
| 84 |
+
k = GenerateKey(n)
|
| 85 |
+
}
|
| 86 |
w.Header().Set("Content-Type", "application/json")
|
| 87 |
resp := map[string]string{"key": k, "name": n}
|
| 88 |
json.NewEncoder(w).Encode(resp)
|