48 lines
1.1 KiB
Go
Raw Normal View History

2017-10-06 20:07:12 +00:00
package editor
import (
2019-06-01 04:55:49 +00:00
"net/http"
2018-03-23 00:43:45 +00:00
"strconv"
2017-10-06 20:07:12 +00:00
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-10-06 20:07:12 +00:00
"github.com/animenotifier/notify.moe/components"
)
// Get ...
2019-06-01 04:55:49 +00:00
func Get(ctx aero.Context) error {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2017-10-06 20:07:12 +00:00
if user == nil || (user.Role != "admin" && user.Role != "editor") {
2019-06-03 06:06:57 +00:00
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
2017-10-06 20:07:12 +00:00
}
2018-03-19 21:55:55 +00:00
ignoreDifferences := arn.FilterIgnoreAnimeDifferences(func(entry *arn.IgnoreAnimeDifference) bool {
return entry.CreatedBy == user.ID
})
score := len(ignoreDifferences) * arn.IgnoreAnimeDifferenceEditorScore
scoreTypes := map[string]int{}
logEntries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool {
return entry.UserID == user.ID
})
for _, entry := range logEntries {
entryScore := entry.EditorScore()
score += entryScore
if entry.ObjectType != "" {
scoreTypes[entry.ObjectType]++
}
}
2018-03-23 00:43:45 +00:00
scoreTitle := ""
for objectType, score := range scoreTypes {
scoreTitle += objectType + ": " + strconv.Itoa(score) + "\n"
}
2019-06-01 04:55:49 +00:00
return ctx.HTML(components.Editor(ctx.Path(), score, scoreTitle, scoreTypes, user))
2017-10-06 20:07:12 +00:00
}