25 lines
569 B
Go
Raw Normal View History

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 {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusNotFound, "Anime not found")
}
return utils.SmartRedirect(ctx, "/anime/"+anime.ID)
}
}