From 482b1c8db5cfeaa20d75ce92fcb10f3ca8433633 Mon Sep 17 00:00:00 2001 From: Factiven Date: Fri, 14 Apr 2023 00:07:02 +0700 Subject: Update 5th --- pages/lib/AniList.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 pages/lib/AniList.js (limited to 'pages/lib/AniList.js') diff --git a/pages/lib/AniList.js b/pages/lib/AniList.js new file mode 100644 index 0000000..f602dad --- /dev/null +++ b/pages/lib/AniList.js @@ -0,0 +1,54 @@ +export async function aniListData({ sort, page = 1 }) { + const resAnilist = await fetch(`https://graphql.anilist.co`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + query: ` + query ( + $id: Int + $page: Int + $perPage: Int + $search: String + $sort: [MediaSort] + ) { + Page(page: $page, perPage: $perPage) { + pageInfo { + total + currentPage + lastPage + hasNextPage + perPage + } + media(id: $id, search: $search, sort: $sort type: ANIME) { + id + idMal + title { + romaji + english + } + coverImage { + extraLarge + } + description + } + } + } + `, + variables: { + page: page, + perPage: 15, + sort, + }, + }), + }); + const anilistData = await resAnilist.json(); + const data = anilistData.data.Page.media; + // console.log(resAnilist); + return { + props: { + data, + }, + }; +} -- cgit v1.2.3