package main import ( "fmt" "net/http" "os" "path/filepath" ) func indexHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "MeowMusicEmbeddedServer") w.Header().Set("Content-Type", "text/html; charset=utf-8") fmt.Printf("[Web Access] Handling request for %s\n", r.URL.Path) // Serve full music app for both / and /app if r.URL.Path == "/" || r.URL.Path == "/app" { appPath := filepath.Join("theme", "full-app.html") if _, err := os.Stat(appPath); err == nil { http.ServeFile(w, r, appPath) fmt.Printf("[Web Access] Return full music app page\n") return } } // Test version available at /test if r.URL.Path == "/test" { testPath := filepath.Join("theme", "test-app.html") if _, err := os.Stat(testPath); err == nil { http.ServeFile(w, r, testPath) fmt.Printf("[Web Access] Return test app page\n") return } } // Access classic interface via /classic if r.URL.Path == "/classic" { indexPath := filepath.Join("theme", "index.html") if _, err := os.Stat(indexPath); err == nil { http.ServeFile(w, r, indexPath) fmt.Printf("[Web Access] Return classic index page\n") return } defaultIndexPage(w) return } if r.URL.Path != "/" { fileHandler(w, r) return } // Fallback to index.html indexPath := filepath.Join("theme", "index.html") // Check if index.html exists in theme directory if _, err := os.Stat(indexPath); os.IsNotExist(err) { defaultIndexPage(w) } else if err != nil { defaultIndexPage(w) } else { http.ServeFile(w, r, indexPath) fmt.Printf("[Web Access] Return custom index pages\n") } } func defaultIndexPage(w http.ResponseWriter) { websiteVersion := "0.0.1-rc-1" websiteNameCN := os.Getenv("WEBSITE_NAME_CN") if websiteNameCN == "" { websiteNameCN = "🎵 音乐搜索" } websiteNameEN := os.Getenv("WEBSITE_NAME_EN") if websiteNameEN == "" { websiteNameEN = "🎵 Music Search" } websiteTitleCN := os.Getenv("WEBSITE_TITLE_CN") if websiteTitleCN == "" { websiteTitleCN = "为嵌入式设备设计的音乐搜索服务器" } websiteTitleEN := os.Getenv("WEBSITE_TITLE_EN") if websiteTitleEN == "" { websiteTitleEN = "Music Search Server for Embedded Devices" } websiteDescCN := os.Getenv("WEBSITE_DESC_CN") if websiteDescCN == "" { websiteDescCN = "搜索并播放您喜爱的音乐" } websiteDescEN := os.Getenv("WEBSITE_DESC_EN") if websiteDescEN == "" { websiteDescEN = "Search and play your favorite music" } websiteKeywordsCN := os.Getenv("WEBSITE_KEYWORDS_CN") if websiteKeywordsCN == "" { websiteKeywordsCN = "音乐, 搜索, 嵌入式" } websiteKeywordsEN := os.Getenv("WEBSITE_KEYWORDS_EN") if websiteKeywordsEN == "" { websiteKeywordsEN = "music, search, embedded" } websiteFavicon := os.Getenv("WEBSITE_FAVICON") if websiteFavicon == "" { websiteFavicon = "/favicon.ico" } websiteBackground := os.Getenv("WEBSITE_BACKGROUND") if websiteBackground == "" { websiteBackground = "/background.webp" } fontawesomeCDN := os.Getenv("FONTAWESOME_CDN") if fontawesomeCDN == "" { fontawesomeCDN = "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" } // Build HTML fmt.Fprintf(w, "") fmt.Fprintf(w, "") fmt.Fprintf(w, "") fmt.Fprintf(w, "") fmt.Fprintf(w, "") fmt.Fprintf(w, "", websiteFavicon) fmt.Fprintf(w, "", fontawesomeCDN) fmt.Fprintf(w, "") // Build body fmt.Fprintf(w, "
") fmt.Fprintf(w, "
") fmt.Fprintf(w, "
") fmt.Fprintf(w, "
") fmt.Fprintf(w, "
") fmt.Fprintf(w, "
1

") fmt.Fprintf(w, "
") fmt.Fprintf(w, "") fmt.Printf("[Web Access] Return default index pages\n") }