// Public routes
http.HandleFunc("/login", logInPage)
- http.Handle("/file-downloads/", http.StripPrefix("/file-downloads/", http.FileServer(http.Dir(config.AudioFilesPath))))
+ http.Handle("/file-downloads/", applyDisposition(http.StripPrefix("/file-downloads/", http.FileServer(http.Dir(config.AudioFilesPath)))))
// Authenticated routes
}
}
+type DispositionMiddleware struct {
+ handler http.Handler
+}
+
+func (m DispositionMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ log.Println("path", r.URL.Path)
+ if r.URL.Path != "/file-downloads/" {
+ w.Header().Add("Content-Disposition", "attachment")
+ }
+ m.handler.ServeHTTP(w, r)
+}
+
+func applyDisposition(handler http.Handler) DispositionMiddleware {
+ return DispositionMiddleware{
+ handler: handler,
+ }
+}
+
type authenticatedHandler func(http.ResponseWriter, *http.Request, User)
type AuthMiddleware struct {
type HeaderData struct {
SelectedMenu string
User User
+ Version string
}
func renderHeader(w http.ResponseWriter, selectedMenu string, user User) {
data := HeaderData{
SelectedMenu: selectedMenu,
User: user,
+ Version: version,
}
err := tmpl.Execute(w, data)
if err != nil {
data := PlaylistsPageData{
Playlists: db.GetPlaylists(),
}
+ for i := range data.Playlists {
+ data.Playlists[i].StartTime = strings.Replace(data.Playlists[i].StartTime, "T", " ", -1)
+ }
tmpl := template.Must(template.ParseFS(content, "templates/playlists.html"))
err := tmpl.Execute(w, data)
if err != nil {
data.Playlist = playlist
data.Entries = db.GetEntriesForPlaylist(id)
}
- renderHeader(w, "radios", user)
+ renderHeader(w, "playlists", user)
tmpl := template.Must(template.ParseFS(content, "templates/playlist.html"))
tmpl.Execute(w, data)
renderFooter(w)