Aniwatch API Version 2 (#66)

BREAKING CHANGE:

* chore: remove files that are not necessary for api v2

* test: update existing tests to use  pkg

* feat: organized aniwatch api envs and add more info about them

* feat: update tsconfig to include strict noUnsed params

* feat(api homepage): revamp api home page

* feat: update wani kuni image

* feat: add dot img

* feat: use hono cors

* feat: use hono rate limiter

* build: remove unnecessary deps, add ones needed and update description

* feat: add hianime routes and their handlers

* feat: update vercel deployment file

* docs: update logo and scraper docs, add envs section

* feat: update main server file

* feat: update peronal deployments caution section
This commit is contained in:
Ritesh Ghosh
2024-10-06 01:13:23 +05:30
committed by GitHub
parent 55810ccf23
commit 46f688ac12
84 changed files with 1028 additions and 3893 deletions
+7 -3
View File
@@ -1,8 +1,12 @@
import { HiAnime } from "aniwatch";
import { expect, test } from "vitest";
import { scrapeAnimeAboutInfo } from "../src/parsers/index.js";
test("returns information about an anime", async () => {
const data = await scrapeAnimeAboutInfo("steinsgate-3");
const animeId = "steinsgate-3";
// npx vitest run animeAboutInfo.test.ts
test(`GET /api/v2/hianime/anime/${animeId}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getInfo(animeId);
expect(data.anime.info.name).not.toEqual(null);
expect(data.recommendedAnimes).not.toEqual([]);
+7 -3
View File
@@ -1,8 +1,12 @@
import { expect, test } from "vitest";
import { scrapeAnimeCategory } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns animes belonging to a category", async () => {
const data = await scrapeAnimeCategory("subbed-anime");
const category = "subbed-anime";
// npx vitest run animeCategory.test.ts
test(`GET /api/v2/hianime/category/${category}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getCategoryAnime(category);
expect(data.animes).not.toEqual([]);
expect(data.genres).not.toEqual([]);
+12 -7
View File
@@ -1,13 +1,18 @@
import { expect, test } from "vitest";
import { scrapeAnimeEpisodeSources } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns anime episode streaming link(s)", async () => {
const data = await scrapeAnimeEpisodeSources(
"steinsgate-3?ep=230",
"hd-1",
"sub"
const animeEpisodeId = "steinsgate-3?ep=230";
const server = "hd-1";
const category = "sub";
// npx vitest run animeEpisodeSrcs.test.ts
test(`GET /api/v2/hianime/episode/sources?animeEpisodeId=${animeEpisodeId}&server=${server}&category=${category}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getEpisodeSources(
animeEpisodeId,
server,
category
);
expect(data.sources).not.toEqual([]);
// expect(data)
});
+7 -3
View File
@@ -1,8 +1,12 @@
import { HiAnime } from "aniwatch";
import { expect, test } from "vitest";
import { scrapeAnimeEpisodes } from "../src/parsers/index.js";
test("returns episodes info of an anime", async () => {
const data = await scrapeAnimeEpisodes("steinsgate-3");
const animeId = "steinsgate-3";
// npx vitest run animeEpisodes.test.ts
test(`GET /api/v2/hianime/anime/${animeId}/episodes`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getEpisodes(animeId);
expect(data.totalEpisodes).not.toEqual(0);
expect(data.episodes).not.toEqual([]);
+9 -3
View File
@@ -1,8 +1,14 @@
import { expect, test } from "vitest";
import { scrapeGenreAnime } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns animes belonging to a genre", async () => {
const data = await scrapeGenreAnime("shounen", 2);
const genreName = "shounen";
const page = 2;
// npx vitest run animeGenre.test.ts
test(`GET /api/v2/hianime/genre/${genreName}?page=${page}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getGenreAnime(genreName, page);
expect(data.animes).not.toEqual([]);
expect(data.genres).not.toEqual([]);
+8 -3
View File
@@ -1,8 +1,13 @@
import { expect, test } from "vitest";
import { scrapeProducerAnimes } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns animes produced by a producer", async () => {
const data = await scrapeProducerAnimes("toei-animation", 2);
const producerName = "toei-animation";
const page = 2;
// npx vitest run animeProducer.test.ts
test(`GET /api/v2/hianime/producer/${producerName}?page=${page}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getProducerAnimes(producerName, page);
expect(data.animes).not.toEqual([]);
expect(data.topAiringAnimes).not.toEqual([]);
+11 -3
View File
@@ -1,8 +1,16 @@
import { expect, test } from "vitest";
import { scrapeAnimeSearch } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns animes related to search query", async () => {
const data = await scrapeAnimeSearch("monster", 2);
const query = "monster";
const page = 1;
const filter: HiAnime.SearchFilters = {
genres: "seinen,psychological",
};
// npx vitest run animeSearch.test.ts
test(`GET /api/v2/hianime/search?q=${query}&page=${page}&genres=${filter.genres}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.search(query, page, filter);
expect(data.animes).not.toEqual([]);
expect(data.mostPopularAnimes).not.toEqual([]);
+7 -3
View File
@@ -1,8 +1,12 @@
import { expect, test } from "vitest";
import { scrapeAnimeSearchSuggestion } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns animes search suggestions related to search query", async () => {
const data = await scrapeAnimeSearchSuggestion("one piece");
const query = "one piece";
// npx vitest run animeSearchSuggestion.test.ts
test(`GET /api/v2/hianime/search/suggestion?q=${query}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.searchSuggestions(query);
expect(data.suggestions).not.toEqual([]);
});
+7 -3
View File
@@ -1,8 +1,12 @@
import { expect, test } from "vitest";
import { scrapeEpisodeServers } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns episode source servers", async () => {
const data = await scrapeEpisodeServers("steinsgate-0-92?ep=2055");
const animeEpisodeId = "steinsgate-0-92?ep=2055";
// npx vitest run episodeServers.test.ts
test(`GET /api/v2/hianime/episode/servers?animeEpisodeId=${animeEpisodeId}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getEpisodeServers(animeEpisodeId);
expect(data.episodeId).not.toEqual(null);
expect(data.episodeNo).not.toEqual(0);
+11 -9
View File
@@ -1,15 +1,17 @@
import { expect, test } from "vitest";
import { scrapeEstimatedSchedule } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
function padZero(num: number) {
return num < 10 ? `0${num}` : num.toString();
}
const padZero = (num: number) => (num < 10 ? `0${num}` : num.toString());
test("returns estimated schedule anime release", async () => {
const d = new Date();
const data = await scrapeEstimatedSchedule(
`${d.getFullYear()}-${padZero(d.getMonth() + 1)}-${padZero(d.getDate())}`
);
const d = new Date();
const date = `${d.getFullYear()}-${padZero(d.getMonth() + 1)}-${padZero(
d.getDate()
)}`;
// npx vitest run estimatedSchedule.test.ts
test(`GET /api/v2/hianime/schedule?date=${date}`, async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getEstimatedSchedule(date);
expect(data.scheduledAnimes).not.toEqual([]);
});
+4 -3
View File
@@ -1,8 +1,9 @@
import { expect, test } from "vitest";
import { scrapeHomePage } from "../src/parsers/index.js";
import { HiAnime } from "aniwatch";
test("returns anime information present in homepage", async () => {
const data = await scrapeHomePage();
test("GET /api/v2/hianime/home", async () => {
const hianime = new HiAnime.Scraper();
const data = await hianime.getHomePage();
expect(data.spotlightAnimes).not.toEqual([]);
expect(data.trendingAnimes).not.toEqual([]);