feat: add AnyIP certificate download with cache and fallback chain

This commit is contained in:
2026-03-01 03:20:31 +08:00
parent 35032c1777
commit 8b9070aac8
3 changed files with 146 additions and 50 deletions

36
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
crypto_tls "crypto/tls"
"embed"
"fmt"
"io/fs"
@@ -12,6 +13,7 @@ import (
"github.com/imbytecat/voicepaste/internal/config"
"github.com/imbytecat/voicepaste/internal/paste"
"github.com/imbytecat/voicepaste/internal/server"
vpTLS "github.com/imbytecat/voicepaste/internal/tls"
"github.com/imbytecat/voicepaste/internal/ws"
)
@@ -50,13 +52,22 @@ func main() {
// Generate auth token
token := server.GenerateToken()
// Build URL
scheme := "https"
if !cfg.Server.TLSAuto {
scheme = "http"
// TLS setup
var tlsResult *vpTLS.Result
scheme := "http"
host := lanIP
if cfg.Server.TLSAuto {
var err error
tlsResult, err = vpTLS.GetTLSConfig(lanIP)
if err != nil {
slog.Error("TLS setup failed", "error", err)
os.Exit(1)
}
scheme = "https"
host = tlsResult.Host
}
url := fmt.Sprintf("%s://%s:%d/?token=%s", scheme, lanIP, cfg.Server.Port, token)
// Build URL
url := fmt.Sprintf("%s://%s:%d/?token=%s", scheme, host, cfg.Server.Port, token)
// Print connection info
fmt.Println()
fmt.Println("╔══════════════════════════════════════╗")
@@ -64,17 +75,24 @@ func main() {
fmt.Println("╚══════════════════════════════════════╝")
fmt.Println()
fmt.Printf(" URL: %s\n", url)
if tlsResult != nil && tlsResult.AnyIP {
fmt.Println(" TLS: AnyIP (browser-trusted)")
} else if cfg.Server.TLSAuto {
fmt.Println(" TLS: self-signed (browser will warn)")
}
fmt.Println()
printQRCode(url)
fmt.Println()
fmt.Println(" Scan QR code with your phone to connect.")
fmt.Println(" Press Ctrl+C to stop.")
fmt.Println()
// Create and start server
webContent, _ := fs.Sub(webFS, "web")
srv := server.New(token, lanIP, webContent)
var serverTLSCfg *crypto_tls.Config
if tlsResult != nil {
serverTLSCfg = tlsResult.Config
}
srv := server.New(token, lanIP, webContent, serverTLSCfg)
// Build ASR factory from config
asrCfg := asr.Config{
AppKey: cfg.Doubao.AppKey,