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

View File

@ -27,3 +27,9 @@ component AnimeEpisodes(anime *arn.Anime, episodes []*arn.Episode, episodeToFrie
.episode-friends
each friend in episodeToFriends[episode.Number] reversed
AvatarNoLink(friend)
if user.Role == "editor" || user.Role == "admin"
.episode-buttons.mountable
button.action(data-action="syncEpisodes", data-trigger="click", data-anime-id=anime.ID)
Icon("refresh")
span Sync

View File

@ -58,3 +58,6 @@ const episode-margin = 0.5rem
width calc(avatar-size / 2)
height calc(avatar-size / 2)
margin-left -0.5rem
.episode-buttons
margin-top content-padding

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()
}