Added redirects for other list services

This commit is contained in:
2018-04-04 16:45:02 +02:00
parent 74daef0df7
commit 534372de24
8 changed files with 53 additions and 38 deletions

24
pages/anime/redirect.go Normal file
View File

@ -0,0 +1,24 @@
package anime
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/utils"
)
// RedirectByMapping redirects to the anime with the given mapping ID.
func RedirectByMapping(mappingName string) func(*aero.Context) string {
return func(ctx *aero.Context) string {
id := ctx.Get("id")
finder := arn.NewAnimeFinder(mappingName)
anime := finder.GetAnime(id)
if anime == nil {
return ctx.Error(http.StatusNotFound, "Anime not found", nil)
}
return utils.SmartRedirect(ctx, "/anime/"+anime.ID)
}
}