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 l'immagine esiste, altrimenti usa quella di default var imageURL string if _, err := os.Stat("." + imgPath); os.IsNotExist(err) { imageURL = defaultImage } // Costruisci gli URL completi audioURL := siteURL + strings.TrimPrefix(mp3Path, "/app") imageURL = siteURL + strings.TrimPrefix(imgPath, "/app") // Genera l'HTML completo del player playerHTML := fmt.Sprintf(`