25 lines
576 B
Go
Raw Normal View History

package anime
import (
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/utils"
)
// RedirectByMapping redirects to the anime with the given mapping ID.
2019-06-01 04:55:49 +00:00
func RedirectByMapping(mappingName string) func(aero.Context) error {
return func(ctx aero.Context) error {
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)
}
}