aboutsummaryrefslogtreecommitdiff
path: root/pages/api/get-media.js
diff options
context:
space:
mode:
Diffstat (limited to 'pages/api/get-media.js')
-rw-r--r--pages/api/get-media.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/pages/api/get-media.js b/pages/api/get-media.js
new file mode 100644
index 0000000..7c45d03
--- /dev/null
+++ b/pages/api/get-media.js
@@ -0,0 +1,78 @@
+// pages/api/anime-media-list.js
+
+export default async function handler(req, res) {
+ const { username, status } = req.body;
+
+ try {
+ const response = await fetch("https://graphql.anilist.co/", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ query: `
+ query ($username: String, $status: MediaListStatus) {
+ MediaListCollection(userName: $username, type: ANIME, status: $status, sort: SCORE_DESC) {
+ user {
+ id
+ name
+ about (asHtml: true)
+ createdAt
+ avatar {
+ large
+ }
+ statistics {
+ anime {
+ count
+ episodesWatched
+ meanScore
+ minutesWatched
+ }
+ }
+ bannerImage
+ mediaListOptions {
+ animeList {
+ sectionOrder
+ }
+ }
+ }
+ lists {
+ status
+ name
+ entries {
+ id
+ mediaId
+ status
+ progress
+ score
+ media {
+ id
+ status
+ title {
+ english
+ romaji
+ }
+ episodes
+ coverImage {
+ large
+ }
+ }
+ }
+ }
+ }
+ }
+ `,
+ variables: {
+ username,
+ status,
+ },
+ }),
+ });
+
+ const data = await response.json();
+ res.status(200).json(data.data.MediaListCollection);
+ } catch (error) {
+ console.error(error);
+ res.status(500).json({ message: "Internal server error" });
+ }
+}