refactor: 移除二维码和交叉编译,改为列出所有 LAN IP 地址;清理依赖

This commit is contained in:
2026-03-01 04:45:27 +08:00
parent 5d17e2e9ac
commit 2dbc916652
6 changed files with 34 additions and 83 deletions

37
main.go
View File

@@ -42,12 +42,13 @@ func main() {
if err := paste.Init(); err != nil {
slog.Warn("clipboard init failed, paste will be unavailable", "err", err)
}
// Detect LAN IP
lanIP, err := server.GetLANIP()
// Detect LAN IPs
lanIPs, err := server.GetLANIPs()
if err != nil {
slog.Error("failed to detect LAN IP", "error", err)
os.Exit(1)
}
lanIP := lanIPs[0] // Use first IP for TLS and server binding
// Read token from config (empty = no auth required)
token := cfg.Security.Token
@@ -66,20 +67,26 @@ func main() {
scheme = "https"
host = tlsResult.Host
}
// Build URL
var url string
if token != "" {
url = fmt.Sprintf("%s://%s:%d/?token=%s", scheme, host, cfg.Server.Port, token)
} else {
url = fmt.Sprintf("%s://%s:%d/", scheme, host, cfg.Server.Port)
}
// Print connection info
fmt.Println()
fmt.Println("╔══════════════════════════════════════╗")
fmt.Println("║ VoicePaste 就绪 ║")
fmt.Println("╚══════════════════════════════════════╝")
fmt.Println()
fmt.Printf(" 地址: %s\n", url)
// Print all accessible addresses
if len(lanIPs) == 1 {
fmt.Printf(" 地址: %s\n", buildURL(scheme, host, cfg.Server.Port, token))
} else {
fmt.Println(" 地址:")
for _, ip := range lanIPs {
h := ip
if tlsResult != nil {
h = tlsResult.Host
}
fmt.Printf(" - %s\n", buildURL(scheme, h, cfg.Server.Port, token))
}
}
if tlsResult != nil && tlsResult.AnyIP {
fmt.Println(" 证书: AnyIP浏览器信任")
} else if cfg.Server.TLSAuto {
@@ -91,9 +98,7 @@ func main() {
fmt.Println(" 认证: 未启用(无需 token")
}
fmt.Println()
printQRCode(url)
fmt.Println()
fmt.Println(" 用手机扫描二维码连接")
fmt.Println(" 在手机浏览器中打开上方地址")
fmt.Println(" 按 Ctrl+C 停止服务")
fmt.Println()
// Create and start server
@@ -142,4 +147,10 @@ func main() {
slog.Error("server error", "error", err)
os.Exit(1)
}
}
func buildURL(scheme, host string, port int, token string) string {
if token != "" {
return fmt.Sprintf("%s://%s:%d/?token=%s", scheme, host, port, token)
}
return fmt.Sprintf("%s://%s:%d/", scheme, host, port)
}