Improved soundtrack components
This commit is contained in:
@ -246,6 +246,8 @@ func Configure(app *aero.Application) {
|
||||
app.Get("/api/test/notification", notifications.Test)
|
||||
app.Get("/api/count/notifications/unseen", notifications.CountUnseen)
|
||||
app.Get("/api/mark/notifications/seen", notifications.MarkNotificationsAsSeen)
|
||||
app.Get("/api/random/soundtrack", soundtrack.Random)
|
||||
app.Get("/api/next/soundtrack", soundtrack.Next)
|
||||
|
||||
// Legal stuff
|
||||
l.Page("/terms", terms.Get)
|
||||
|
29
pages/soundtrack/random.go
Normal file
29
pages/soundtrack/random.go
Normal file
@ -0,0 +1,29 @@
|
||||
package soundtrack
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
)
|
||||
|
||||
// Random returns a random soundtrack.
|
||||
func Random(ctx *aero.Context) string {
|
||||
tracks := arn.AllSoundTracks()
|
||||
index := rand.Intn(len(tracks))
|
||||
track := tracks[index]
|
||||
|
||||
return ctx.JSON(track)
|
||||
}
|
||||
|
||||
// Next returns the next soundtrack for the audio player.
|
||||
func Next(ctx *aero.Context) string {
|
||||
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||
return track.File != ""
|
||||
})
|
||||
|
||||
index := rand.Intn(len(tracks))
|
||||
track := tracks[index]
|
||||
|
||||
return ctx.JSON(track)
|
||||
}
|
Reference in New Issue
Block a user