Added episode sync for editors
This commit is contained in:
parent
8bd56db757
commit
81f18ec233
@ -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
|
||||
|
@ -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
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()
|
||||
}
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/notify.moe/arn"
|
||||
"github.com/animenotifier/notify.moe/pages/anime"
|
||||
"github.com/animenotifier/notify.moe/pages/animeimport"
|
||||
"github.com/animenotifier/notify.moe/pages/animelist"
|
||||
"github.com/animenotifier/notify.moe/pages/api"
|
||||
@ -76,4 +77,5 @@ func Register(app *aero.Application) {
|
||||
|
||||
// Jobs
|
||||
app.Post("/api/job/:job/start", jobs.Start)
|
||||
app.Post("/api/anime/:id/sync-episodes", anime.SyncEpisodes)
|
||||
}
|
||||
|
@ -105,3 +105,21 @@ export async function startJob(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||
await arn.post(`/api/job/${jobName}/start`)
|
||||
arn.reloadContent()
|
||||
}
|
||||
|
||||
// Sync episodes
|
||||
export async function syncEpisodes(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||
if(!confirm("Are you sure you want to start the episode sync?")) {
|
||||
return
|
||||
}
|
||||
|
||||
const animeId = button.dataset.animeId
|
||||
|
||||
arn.statusMessage.showInfo("Started episode sync.", -1)
|
||||
|
||||
try {
|
||||
await arn.post(`/api/anime/${animeId}/sync-episodes`)
|
||||
arn.statusMessage.showInfo("Finished episode sync.")
|
||||
} catch(err) {
|
||||
arn.statusMessage.showError(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user