Skip to content

Commit

Permalink
templates: make SongFileSize work with both Song and PendingSong
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Jan 4, 2025
1 parent 9869066 commit 5c27981
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v4 v4.3.0
github.com/davecgh/go-spew v1.1.1
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/httprate v0.14.1
github.com/go-sql-driver/mysql v1.8.1
github.com/golang-migrate/migrate/v4 v4.18.1
Expand Down Expand Up @@ -96,7 +97,6 @@ require (
github.com/docker/docker v27.4.0+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
23 changes: 21 additions & 2 deletions templates/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@ func (sf *StatefulFuncs) Status() radio.Status {
return sf.status.Latest()
}

func (sf *StatefulFuncs) SongFileSize(song radio.Song) string {
path := util.AbsolutePath(sf.Conf().MusicPath, song.FilePath)
func (sf *StatefulFuncs) SongFileSize(song any) string {
var path string
switch s := song.(type) {
case radio.Song:
path = s.FilePath
case *radio.Song:
if s != nil {
path = s.FilePath
}
case radio.PendingSong:
path = s.FilePath
case *radio.PendingSong:
if s != nil {
path = s.FilePath
}
default:
return "??? MiB"
}

// make the path absolute
path = util.AbsolutePath(sf.Conf().MusicPath, path)

fi, err := os.Stat(path)
if err != nil {
Expand Down

0 comments on commit 5c27981

Please sign in to comment.