feat: create route to return title information

Summary:

Test Plan:
This commit is contained in:
2024-05-15 23:03:08 -04:00
parent 695a1bb4cd
commit 68c082493e
18 changed files with 1367 additions and 4 deletions

602
src/mocks/amvstrm/title.ts Normal file
View File

@@ -0,0 +1,602 @@
import { HttpResponse, http } from "msw";
export function getAmvstrmTitle() {
return http.get(
"https://api-amvstrm.nyt92.eu.org/api/v2/info/:aniListId",
({ params }) => {
const aniListId = Number(params["aniListId"] as string);
if (aniListId == -1) {
return HttpResponse.json({
code: 404,
message:
"The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.",
});
}
if (aniListId == 50) {
return HttpResponse.json({
code: 200,
message: "success",
id: 151807,
idMal: 52299,
id_provider: {
idGogo: "ore-dake-level-up-na-ken",
idGogoDub: "ore-dake-level-up-na-ken-korean-dub",
idZoro: "solo-leveling-18718",
id9anime: "solo-leveling.3rpv2",
idPahe: "5421",
},
title: {
romaji: "Ore dake Level Up na Ken",
english: "Solo Leveling",
native: "俺だけレベルアップな件",
userPreferred: "Ore dake Level Up na Ken",
},
dub: true,
description:
"They say whatever doesnt kill you makes you stronger, but thats not the case for the worlds weakest hunter Sung Jinwoo. After being brutally slaughtered by monsters in a high-ranking dungeon, Jinwoo came back with the System, a program only he could see, thats leveling him up in every way. Now, hes inspired to discover the secrets behind his powers and the dungeon that spawned them.<br>\n<br>\n(Source: Crunchyroll) <br><br>",
coverImage: {
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx151807-yxY3olrjZH4k.png",
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx151807-yxY3olrjZH4k.png",
color: "#35bbf1",
},
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/151807-37yfQA3ym8PA.jpg",
genres: ["Action", "Adventure", "Fantasy"],
tags: [
{
id: 604,
name: "Dungeon",
},
{
id: 82,
name: "Male Protagonist",
},
{
id: 321,
name: "Urban Fantasy",
},
{
id: 66,
name: "Super Power",
},
{
id: 29,
name: "Magic",
},
{
id: 1243,
name: "Necromancy",
},
{
id: 326,
name: "Cultivation",
},
{
id: 111,
name: "War",
},
{
id: 104,
name: "Anti-Hero",
},
{
id: 94,
name: "Gore",
},
{
id: 636,
name: "Cosmic Horror",
},
{
id: 85,
name: "Tragedy",
},
{
id: 43,
name: "Swordplay",
},
{
id: 56,
name: "Shounen",
},
{
id: 146,
name: "Alternate Universe",
},
{
id: 96,
name: "Time Manipulation",
},
{
id: 1068,
name: "Angels",
},
{
id: 93,
name: "Post-Apocalyptic",
},
{
id: 217,
name: "Dystopian",
},
{
id: 1310,
name: "Travel",
},
{
id: 1045,
name: "Heterosexual",
},
{
id: 488,
name: "Age Regression",
},
{
id: 244,
name: "Isekai",
},
{
id: 171,
name: "Bullying",
},
{
id: 224,
name: "Dragons",
},
{
id: 255,
name: "Ninja",
},
],
status: "FINISHED",
format: "TV",
episodes: 12,
year: 2024,
season: "WINTER",
duration: 24,
startIn: {
year: 2024,
month: 1,
day: 7,
},
endIn: {
year: 2024,
month: 3,
day: 31,
},
nextair: null,
score: {
averageScore: 83,
decimalScore: 8.3,
},
popularity: 196143,
siteUrl: "https://anilist.co/anime/151807",
trailer: {
id: "HkIKAnwLZCw",
site: "youtube",
thumbnail: "https://i.ytimg.com/vi/HkIKAnwLZCw/hqdefault.jpg",
},
studios: [
{
name: "A-1 Pictures",
},
{
name: "Aniplex",
},
{
name: "Netmarble",
},
{
name: "D&C MEDIA",
},
{
name: "Kakao piccoma",
},
{
name: "Crunchyroll",
},
],
relation: [
{
id: 105398,
idMal: 121496,
title: {
romaji: "Na Honjaman Level Up",
english: "Solo Leveling",
native: "나 혼자만 레벨업",
userPreferred: "Na Honjaman Level Up",
},
coverImage: {
large:
"https://s4.anilist.co/file/anilistcdn/media/manga/cover/medium/bx105398-b673Vt5ZSuz3.jpg",
medium:
"https://s4.anilist.co/file/anilistcdn/media/manga/cover/small/bx105398-b673Vt5ZSuz3.jpg",
color: null,
},
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/manga/banner/105398-4UrEhdqZukrg.jpg",
genres: ["Action", "Adventure", "Fantasy"],
tags: [
{
id: 604,
name: "Dungeon",
},
{
id: 82,
name: "Male Protagonist",
},
{
id: 111,
name: "War",
},
{
id: 66,
name: "Super Power",
},
{
id: 207,
name: "Full Color",
},
{
id: 29,
name: "Magic",
},
{
id: 1243,
name: "Necromancy",
},
{
id: 321,
name: "Urban Fantasy",
},
{
id: 253,
name: "Gods",
},
{
id: 109,
name: "Primarily Adult Cast",
},
{
id: 103,
name: "Politics",
},
{
id: 93,
name: "Post-Apocalyptic",
},
{
id: 15,
name: "Demons",
},
{
id: 85,
name: "Tragedy",
},
{
id: 308,
name: "Video Games",
},
{
id: 365,
name: "Memory Manipulation",
},
{
id: 96,
name: "Time Manipulation",
},
{
id: 198,
name: "Foreign",
},
{
id: 1564,
name: "Estranged Family",
},
{
id: 171,
name: "Bullying",
},
{
id: 488,
name: "Age Regression",
},
{
id: 104,
name: "Anti-Hero",
},
{
id: 322,
name: "Assassins",
},
{
id: 774,
name: "Chimera",
},
{
id: 1045,
name: "Heterosexual",
},
{
id: 516,
name: "Language Barrier",
},
{
id: 153,
name: "Time Skip",
},
],
type: "MANGA",
format: "MANGA",
status: "FINISHED",
episodes: null,
duration: null,
averageScore: 85,
season: null,
},
{
id: 176496,
idMal: 58567,
title: {
romaji:
"Ore dake Level Up na Ken: Season 2 - Arise from the Shadow",
english: "Solo Leveling Season 2 -Arise from the Shadow-",
native:
"俺だけレベルアップな件 Season 2 -Arise from the Shadow-",
userPreferred:
"Ore dake Level Up na Ken: Season 2 - Arise from the Shadow",
},
coverImage: {
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx176496-r6oXxEqdZL0n.jpg",
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx176496-r6oXxEqdZL0n.jpg",
color: "#a1bbe4",
},
bannerImage: null,
genres: ["Action", "Adventure", "Fantasy"],
tags: [
{
id: 1243,
name: "Necromancy",
},
{
id: 604,
name: "Dungeon",
},
],
type: "ANIME",
format: "TV",
status: "NOT_YET_RELEASED",
episodes: null,
duration: null,
averageScore: null,
season: null,
},
],
});
}
return HttpResponse.json({
code: 200,
message: "success",
id: 135643,
idMal: 49210,
id_provider: {
idGogo: "grimm-kumikyoku-dub",
idGogoDub: "grimm-kumikyoku",
idZoro: "the-grimm-variations-19092",
id9anime: "grimm-kumikyoku.qxvzn",
idPahe: "",
},
title: {
romaji: "Grimm Kumikyoku",
english: "The Grimm Variations",
native: "グリム組曲",
userPreferred: "Grimm Kumikyoku",
},
dub: true,
description:
'Once upon a time, brothers Jacob and Wilhelm collected fairy tales from across the land and made them into a book. They also had a much younger sister, the innocent and curious Charlotte, who they loved very much. One day, while the brothers were telling Charlotte a fairy tale like usual, they saw that she had a somewhat melancholy look on her face. She asked them, "Do you suppose they really lived happily ever after?"\n<br><br>\nThe pages of Grimms\' Fairy Tales, written by Jacob and Wilhelm, are now presented from the unique perspective of Charlotte, who sees the stories quite differently from her brothers.\n<br><br>\n(Source: Netflix Anime)',
coverImage: {
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx135643-2kJt86K9Db9P.jpg",
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx135643-2kJt86K9Db9P.jpg",
color: "#fea150",
},
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/135643-cmQZCR3z9dB5.jpg",
genres: ["Fantasy", "Thriller"],
tags: [
{
id: 400,
name: "Fairy Tale",
},
{
id: 193,
name: "Episodic",
},
{
id: 471,
name: "Anthology",
},
{
id: 227,
name: "Classic Literature",
},
{
id: 179,
name: "Witch",
},
{
id: 1219,
name: "Disability",
},
{
id: 93,
name: "Post-Apocalyptic",
},
{
id: 94,
name: "Gore",
},
{
id: 25,
name: "Historical",
},
{
id: 250,
name: "Rural",
},
{
id: 394,
name: "Writing",
},
{
id: 29,
name: "Magic",
},
{
id: 161,
name: "Bar",
},
{
id: 1578,
name: "Arranged Marriage",
},
{
id: 654,
name: "Denpa",
},
{
id: 217,
name: "Dystopian",
},
{
id: 598,
name: "Elf",
},
{
id: 456,
name: "Conspiracy",
},
{
id: 63,
name: "Space",
},
{
id: 364,
name: "Augmented Reality",
},
{
id: 112,
name: "Virtual World",
},
{
id: 639,
name: "Body Horror",
},
{
id: 163,
name: "Yandere",
},
{
id: 154,
name: "Body Swapping",
},
{
id: 100,
name: "Nudity",
},
],
status: "FINISHED",
format: "ONA",
episodes: 6,
year: 2024,
season: "SPRING",
duration: 44,
startIn: {
year: 2024,
month: 4,
day: 17,
},
endIn: {
year: 2024,
month: 4,
day: 17,
},
nextair: null,
score: {
averageScore: 66,
decimalScore: 6.6,
},
popularity: 8486,
siteUrl: "https://anilist.co/anime/135643",
trailer: {
id: "bTU3detmX_I",
site: "youtube",
thumbnail: "https://i.ytimg.com/vi/bTU3detmX_I/hqdefault.jpg",
},
studios: [
{
name: "Netflix",
},
{
name: "Wit Studio",
},
],
relation: [
{
id: 177039,
idMal: 169338,
title: {
romaji: "Grimm Kumikyoku",
english: null,
native: "グリム組曲",
userPreferred: "Grimm Kumikyoku",
},
coverImage: {
large:
"https://s4.anilist.co/file/anilistcdn/media/manga/cover/medium/bx177039-672FYniIpHIL.jpg",
medium:
"https://s4.anilist.co/file/anilistcdn/media/manga/cover/small/bx177039-672FYniIpHIL.jpg",
color: "#865028",
},
bannerImage: null,
genres: ["Fantasy", "Thriller"],
tags: [
{
id: 400,
name: "Fairy Tale",
},
{
id: 94,
name: "Gore",
},
{
id: 85,
name: "Tragedy",
},
{
id: 63,
name: "Space",
},
],
type: "MANGA",
format: "MANGA",
status: "RELEASING",
episodes: null,
duration: null,
averageScore: null,
season: null,
},
],
});
},
);
}

12
src/mocks/anify/title.ts Normal file
View File

@@ -0,0 +1,12 @@
import { HttpResponse, http } from "msw";
export function getAnifyTitle() {
return http.get(`https://api.anify.tv/info`, ({ request }) => {
// Construct a URL instance out of the intercepted request.
const url = new URL(request.url);
const id = url.searchParams.get("id");
// TODO: Actually return a response
return HttpResponse.json({ bannerImage: null, countryOfOrigin: "JP" });
});
}

View File

@@ -0,0 +1,70 @@
import { HttpResponse, graphql } from "msw";
export function getAnilistTitle() {
return graphql.query(
"GetTitle",
({ variables: { id }, request: { headers } }) => {
console.log(
`Intercepting GetTitle query with ID ${id} and Authorization header ${headers.get("authorization")}`,
);
if (id === -1 || id === 50) {
return HttpResponse.json({
errors: [
{
message: "Not Found.",
status: 404,
locations: [
{
line: 2,
column: 2,
},
],
},
],
data: {
Media: null,
},
});
}
return HttpResponse.json({
data: {
Media: {
id: 135643,
idMal: 49210,
title: {
english: "The Grimm Variations",
userPreferred: "The Grimm Variations",
},
description:
'Once upon a time, brothers Jacob and Wilhelm collected fairy tales from across the land and made them into a book. They also had a much younger sister, the innocent and curious Charlotte, who they loved very much. One day, while the brothers were telling Charlotte a fairy tale like usual, they saw that she had a somewhat melancholy look on her face. She asked them, "Do you suppose they really lived happily ever after?"\n<br><br>\nThe pages of Grimms\' Fairy Tales, written by Jacob and Wilhelm, are now presented from the unique perspective of Charlotte, who sees the stories quite differently from her brothers.\n<br><br>\n(Source: Netflix Anime)',
episodes: 6,
genres: ["Fantasy", "Thriller"],
status: "FINISHED",
bannerImage:
"https://s4.anilist.co/file/anilistcdn/media/anime/banner/135643-cmQZCR3z9dB5.jpg",
averageScore: 66,
coverImage: {
extraLarge:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx135643-2kJt86K9Db9P.jpg",
large:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/medium/bx135643-2kJt86K9Db9P.jpg",
medium:
"https://s4.anilist.co/file/anilistcdn/media/anime/cover/small/bx135643-2kJt86K9Db9P.jpg",
},
countryOfOrigin: "JP",
mediaListEntry: headers.has("authorization")
? {
id: 402665918,
progress: 1,
status: "CURRENT",
}
: null,
nextAiringEpisode: null,
},
},
});
},
);
}

View File

@@ -1 +1,5 @@
export const handlers = [];
import { getAmvstrmTitle } from "./amvstrm/title";
import { getAnifyTitle } from "./anify/title";
import { getAnilistTitle } from "./anilist/title";
export const handlers = [getAnilistTitle(), getAmvstrmTitle(), getAnifyTitle()];