Added episode sync for editors

This commit is contained in:
2020-11-07 07:45:38 +09:00
parent 8bd56db757
commit 81f18ec233
5 changed files with 60 additions and 0 deletions

31
pages/anime/sync.go Normal file
View File

@ -0,0 +1,31 @@
package anime
import (
"net/http"
"github.com/animenotifier/notify.moe/arn"
"github.com/aerogo/aero"
)
// SyncEpisodes syncs the episodes with an external site.
func SyncEpisodes(ctx aero.Context) error {
user := arn.GetUserFromContext(ctx)
animeID := ctx.Get("id")
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
if user.Role != "editor" && user.Role != "admin" {
return ctx.Error(http.StatusUnauthorized, "Not authorized")
}
anime, err := arn.GetAnime(animeID)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
return anime.RefreshEpisodes()
}