2018-04-04 14:45:02 +00:00
|
|
|
package anime
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-04-04 14:45:02 +00:00
|
|
|
"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 {
|
2018-04-04 14:45:02 +00:00
|
|
|
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")
|
2018-04-04 14:45:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return utils.SmartRedirect(ctx, "/anime/"+anime.ID)
|
|
|
|
}
|
|
|
|
}
|