package main import ( "fmt" "net/http" "os" "path/filepath" "strings" ) var ( audioBasePath = audioDir // percorso base dei file audio imageBasePath = coversDir // percorso base delle immagini badgeBasePath = "/badge/" // percorso per i badge siteURL = baseURL defaultImage = podLogo ) func badgeHandler(w http.ResponseWriter, r *http.Request) { // Estrai il nome dell'episodio dall'URL episode := strings.TrimPrefix(r.URL.Path, badgeBasePath) if episode == "" { http.Error(w, "Episode name required", http.StatusBadRequest) return } // Costruisci i percorsi dei file mp3Path := filepath.Join(audioBasePath, episode+".mp3") imgPath := filepath.Join(imageBasePath, episode+".jpg") // Verifica se il file MP3 esiste if _, err := os.Stat("." + mp3Path); os.IsNotExist(err) { http.Error(w, "Episode not found", http.StatusNotFound) return } // Costruisci gli URL completi audioURL := siteURL + mp3Path imageURL := siteURL + imgPath // Verifica se l'immagine esiste, altrimenti usa quella di default if _, err := os.Stat("." + imgPath); os.IsNotExist(err) { imageURL = defaultImage } // Genera l'HTML completo del player playerHTML := fmt.Sprintf(`