var config ServerConfig = NewServerConfig()
-// Channel that will be closed and recreated every time the playlists change
-var playlistChangeWait = make(chan bool)
-
func main() {
configFlag := flag.String("c", "", "path to configuration file")
// TODO: support this
InitDatabase()
defer db.CloseDatabase()
+ InitCommandRouter()
+ InitPlaylists()
InitAudioFiles(config.AudioFilesPath)
InitServerStatus()
http.HandleFunc("/login", logInPage)
http.HandleFunc("/logout", logOutPage)
http.HandleFunc("/secret", secretPage)
+ http.HandleFunc("/stop", stopPage)
http.HandleFunc("/playlist/", playlistSection)
http.HandleFunc("/file/", fileSection)
}
db.SetEntriesForPlaylist(cleanedEntries, id)
// Notify connected radios
- close(playlistChangeWait)
- playlistChangeWait = make(chan bool)
+ playlists.NotifyChanges()
}
http.Redirect(w, r, "/playlist/", http.StatusFound)
}
return
}
db.DeletePlaylist(id)
+ playlists.NotifyChanges()
}
http.Redirect(w, r, "/playlist/", http.StatusFound)
}
tmpl := template.Must(template.ParseFiles("templates/logout.html"))
tmpl.Execute(w, nil)
}
+
+func stopPage(w http.ResponseWriter, r *http.Request) {
+ _, err := currentUser(w, r)
+ if err != nil {
+ http.Redirect(w, r, "/login", http.StatusFound)
+ return
+ }
+ r.ParseForm()
+ radioId, err := strconv.Atoi(r.Form.Get("radioId"))
+ if err != nil {
+ http.NotFound(w, r)
+ return
+ }
+ commandRouter.Stop(radioId)
+ http.Redirect(w, r, "/", http.StatusFound)
+}