Added episode sync for editors
This commit is contained in:
31
pages/anime/sync.go
Normal file
31
pages/anime/sync.go
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user