2017-07-22 13:04:54 +00:00
|
|
|
package amvs
|
|
|
|
|
|
|
|
import (
|
2018-04-15 09:14:11 +00:00
|
|
|
"sort"
|
|
|
|
|
2017-07-22 13:04:54 +00:00
|
|
|
"github.com/aerogo/aero"
|
2018-04-15 09:14:11 +00:00
|
|
|
"github.com/animenotifier/arn"
|
2018-04-14 21:23:00 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2017-07-22 13:04:54 +00:00
|
|
|
)
|
|
|
|
|
2018-04-14 21:23:00 +00:00
|
|
|
// Latest AMVs.
|
|
|
|
func Latest(ctx *aero.Context) string {
|
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
|
2018-04-15 09:14:11 +00:00
|
|
|
amvs := arn.FilterAMVs(func(amv *arn.AMV) bool {
|
|
|
|
return !amv.IsDraft
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(amvs, func(i, j int) bool {
|
|
|
|
return amvs[i].Created > amvs[j].Created
|
|
|
|
})
|
|
|
|
|
|
|
|
return ctx.HTML(components.AMVs(amvs, -1, "", user))
|
2018-04-14 21:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Best AMVs.
|
|
|
|
func Best(ctx *aero.Context) string {
|
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
|
2018-04-15 09:14:11 +00:00
|
|
|
amvs := arn.FilterAMVs(func(amv *arn.AMV) bool {
|
|
|
|
return !amv.IsDraft
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(amvs, func(i, j int) bool {
|
|
|
|
if len(amvs[i].Likes) == len(amvs[j].Likes) {
|
|
|
|
return amvs[i].Title.String() < amvs[j].Title.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(amvs[i].Likes) > len(amvs[j].Likes)
|
|
|
|
})
|
|
|
|
|
|
|
|
return ctx.HTML(components.AMVs(amvs, -1, "", user))
|
2017-07-22 13:04:54 +00:00
|
|
|
}
|