aboutsummaryrefslogtreecommitdiff
path: root/pages/lib/AniList.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-04-14 00:07:02 +0700
committerFactiven <[email protected]>2023-04-14 00:07:02 +0700
commit482b1c8db5cfeaa20d75ce92fcb10f3ca8433633 (patch)
treef0c12d3acb6bd8ce43e63e01527c97a62dba7e9c /pages/lib/AniList.js
parentUpdate index.js (diff)
downloadmoopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.tar.xz
moopa-482b1c8db5cfeaa20d75ce92fcb10f3ca8433633.zip
Update 5th
Diffstat (limited to 'pages/lib/AniList.js')
-rw-r--r--pages/lib/AniList.js54
1 files changed, 54 insertions, 0 deletions
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,
+ },
+ };
+}