Spaces:
Paused
Paused
load keys from env backup on startup
Browse files- internal/handler/keys.go +9 -1
- main.go +1 -0
internal/handler/keys.go
CHANGED
|
@@ -26,7 +26,15 @@ const p = "/data/keys.json"
|
|
| 26 |
func init() {
|
| 27 |
os.MkdirAll("/data", 0755)
|
| 28 |
f, _ := os.ReadFile(p)
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
if s.Keys == nil { s.Keys = make(map[string]*KeyData) }
|
| 31 |
}
|
| 32 |
|
|
|
|
| 26 |
func init() {
|
| 27 |
os.MkdirAll("/data", 0755)
|
| 28 |
f, _ := os.ReadFile(p)
|
| 29 |
+
if len(f) > 0 {
|
| 30 |
+
json.Unmarshal(f, &s)
|
| 31 |
+
} else if backup := os.Getenv("BACKUP_KEYS"); backup != "" {
|
| 32 |
+
var keys map[string]*KeyData
|
| 33 |
+
if json.Unmarshal([]byte(backup), &keys) == nil {
|
| 34 |
+
s.Keys = keys
|
| 35 |
+
save()
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
if s.Keys == nil { s.Keys = make(map[string]*KeyData) }
|
| 39 |
}
|
| 40 |
|
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("/v1/models", handler.HandleModels)
|
| 21 |
http.HandleFunc("/v1/chat/completions", handler.HandleChatCompletions)
|
| 22 |
http.HandleFunc("/v1/messages", handler.HandleMessages)
|
|
|
|
| 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)
|
| 23 |
http.HandleFunc("/v1/messages", handler.HandleMessages)
|