diff options
| author | Bobby <[email protected]> | 2026-02-26 14:28:21 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-26 14:28:21 +0530 |
| commit | 627c2c239e0a44b6363a9f02235a73f5e2c81d2e (patch) | |
| tree | 6c7b3cad8a5fb42c5649905a20800edf8e63f666 /controllers | |
| parent | aa4cf5ff588c9082282ee57074199dc7d2a37e09 (diff) | |
| download | metachan-627c2c239e0a44b6363a9f02235a73f5e2c81d2e.tar.xz metachan-627c2c239e0a44b6363a9f02235a73f5e2c81d2e.zip | |
Add MAL client and anime parsing functionality
- Implemented a new CloudflareClient to handle requests with randomized browser profiles.
- Created structures and functions for parsing anime data from MyAnimeList (MAL), including anime details, episodes, and theme songs.
- Added enums for anime types, statuses, sources, and ratings.
- Developed utility functions for making HTTP requests with rate limiting and error handling.
- Introduced image handling for anime covers and thumbnails.
- Established a comprehensive data model for anime, including fields for statistics, trailers, and external links.
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/anime.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/controllers/anime.go b/controllers/anime.go index 2418c67..be740ce 100644 --- a/controllers/anime.go +++ b/controllers/anime.go @@ -2,26 +2,24 @@ package controllers import ( "errors" - "metachan/enums" - "metachan/repositories" + "metachan/utils/mal" "metachan/utils/meta" + "strconv" "github.com/gofiber/fiber/v2" ) func GetAnime(c *fiber.Ctx) error { - id := meta.Request(c).MustHave().Param("id") - provider := meta.Request(c).Default("mal").Query("provider") + idString := meta.Request(c).MustHave().Param("id") - switch provider { - case "mal", "anilist": - default: - return BadRequest(c, errors.New("invalid provider")) + malID, parseErr := strconv.Atoi(idString) + if parseErr != nil { + return BadRequest(c, errors.New("invalid MAL ID")) } - anime, err := repositories.GetAnime(enums.MappingType(provider), id) - if err != nil { - return NotFound(c, err) + anime, fetchErr := mal.GetAnimeByMALID(malID) + if fetchErr != nil { + return NotFound(c, fetchErr) } return c.JSON(anime) |
