2016-11-19 23:54:31 +09:00
package dashboard
import (
"github.com/aerogo/aero"
2017-06-08 01:14:45 +02:00
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-06-07 23:37:13 +02:00
"github.com/animenotifier/notify.moe/utils"
2016-11-19 23:54:31 +09:00
)
2016-12-06 12:36:31 +09:00
const maxPosts = 5
2016-11-22 12:34:59 +09:00
2016-11-19 23:54:31 +09:00
// Get ...
func Get ( ctx * aero . Context ) string {
2017-06-08 01:14:45 +02:00
user := utils . GetUser ( ctx )
2016-11-22 12:34:59 +09:00
2017-06-08 01:14:45 +02:00
if user != nil {
posts , err := arn . GetPosts ( )
2016-11-22 12:34:59 +09:00
2017-06-08 01:14:45 +02:00
if err != nil {
return ctx . Error ( 500 , "Error fetching posts" , err )
}
2016-11-22 12:34:59 +09:00
2017-06-08 01:14:45 +02:00
arn . SortPostsLatestFirst ( posts )
2017-06-07 21:12:59 +02:00
2017-06-08 01:14:45 +02:00
if len ( posts ) > maxPosts {
posts = posts [ : maxPosts ]
}
2017-06-07 21:12:59 +02:00
2017-06-08 01:14:45 +02:00
return ctx . HTML ( components . Dashboard ( posts ) )
2017-06-07 21:12:59 +02:00
}
2017-06-08 21:54:39 +02:00
return ctx . HTML ( "ARN 4.0 is currently under construction.<br><a href='https://paypal.me/blitzprog' target='_blank' rel='noopener'>Support the development</a><br><a href='/auth/google'>Login via Google</a>" )
2016-11-19 23:54:31 +09:00
}