42 lines
992 B
Go
Raw Normal View History

2017-10-02 04:29:58 +00:00
package soundtrack
2017-06-27 22:16:45 +00:00
import (
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-06-27 22:16:45 +00:00
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/server/middleware"
2017-06-27 22:16:45 +00:00
)
2017-07-13 06:23:20 +00:00
// Get track.
2019-06-01 04:55:49 +00:00
func Get(ctx aero.Context) error {
2017-06-27 22:16:45 +00:00
id := ctx.Get("id")
track, err := arn.GetSoundTrack(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Track not found", err)
}
user := arn.GetUserFromContext(ctx)
animes := track.Anime()
relatedTracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool {
return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(animes, t)
})
2019-06-01 04:55:49 +00:00
customCtx := ctx.(*middleware.OpenGraphContext)
2019-06-05 07:18:04 +00:00
customCtx.OpenGraph = getOpenGraph(track)
return ctx.HTML(components.SoundTrackPage(track, relatedTracks, user))
2018-04-13 10:20:13 +00:00
}
func isRelated(animes []*arn.Anime, track *arn.SoundTrack) bool {
for _, anime := range animes {
if arn.Contains(track.Tags, "anime:"+anime.ID) {
return true
}
}
return false
}