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"
|
2019-11-18 09:39:59 +00:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
2020-02-12 04:30:35 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
|
|
|
animes := track.Anime()
|
|
|
|
|
2020-02-11 11:43:50 +00:00
|
|
|
relatedTracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool {
|
2020-02-12 04:30:35 +00:00
|
|
|
return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(animes, t)
|
2020-02-11 11:43:50 +00:00
|
|
|
})
|
2020-02-10 23:11:09 +00:00
|
|
|
|
2019-06-01 04:55:49 +00:00
|
|
|
customCtx := ctx.(*middleware.OpenGraphContext)
|
2019-06-05 07:18:04 +00:00
|
|
|
customCtx.OpenGraph = getOpenGraph(track)
|
2020-02-10 23:11:09 +00:00
|
|
|
return ctx.HTML(components.SoundTrackPage(track, relatedTracks, user))
|
2018-04-13 10:20:13 +00:00
|
|
|
}
|
2020-02-11 11:43:50 +00:00
|
|
|
|
2020-02-12 04:30:35 +00:00
|
|
|
func isRelated(animes []*arn.Anime, track *arn.SoundTrack) bool {
|
|
|
|
for _, anime := range animes {
|
2020-02-11 11:43:50 +00:00
|
|
|
if arn.Contains(track.Tags, "anime:"+anime.ID) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|