fix: token 改为配置文件读取,不再自动生成;UI 全部汉化

This commit is contained in:
2026-03-01 04:09:55 +08:00
parent 2ce0323ba5
commit 9420d43392
5 changed files with 36 additions and 29 deletions

View File

@@ -11,6 +11,11 @@ type DoubaoConfig struct {
ResourceID string `yaml:"resource_id"`
}
// SecurityConfig holds authentication settings.
type SecurityConfig struct {
Token string `yaml:"token"`
}
// ServerConfig holds server settings.
type ServerConfig struct {
Port int `yaml:"port"`
@@ -19,8 +24,9 @@ type ServerConfig struct {
// Config is the top-level configuration.
type Config struct {
Doubao DoubaoConfig `yaml:"doubao"`
Server ServerConfig `yaml:"server"`
Doubao DoubaoConfig `yaml:"doubao"`
Server ServerConfig `yaml:"server"`
Security SecurityConfig `yaml:"security"`
}
// defaults returns a Config with default values.

View File

@@ -1,10 +1,7 @@
package server
import (
"crypto/rand"
"encoding/hex"
"fmt"
"log/slog"
"net"
)
@@ -22,13 +19,3 @@ func GetLANIP() (string, error) {
return "", fmt.Errorf("no LAN IP found")
}
// GenerateToken creates a cryptographically random token for WS auth.
func GenerateToken() string {
b := make([]byte, 16)
if _, err := rand.Read(b); err != nil {
slog.Error("failed to generate token", "error", err)
// Fallback to a less secure but functional token
return "voicepaste-fallback-token"
}
return hex.EncodeToString(b)
}