refactor: replace amvstrm source with aniwatch

This commit is contained in:
2024-08-18 21:37:13 -04:00
parent 0bcc547ede
commit 1a06eb51eb
14 changed files with 179 additions and 262 deletions

View File

@@ -1,31 +0,0 @@
export async function fetchSearchResultsFromAmvstrm(
query: string,
page: number,
limit: number,
) {
return fetch(
`https://amvstrm.up.railway.app/api/v2/search?q=${query}&p=${page}&limit=${limit}`,
)
.then((res) => res.json<any>())
.then(({ pageInfo: { hasNextPage }, results }) => ({
hasNextPage,
results: results.map(
({
id,
title: { userPreferred, english },
coverImage: { extraLarge, large, medium },
}: any) => ({
id,
title: { userPreferred, english },
coverImage: { extraLarge, large, medium },
}),
),
}))
.then((searchResults) => {
if (searchResults.results.length === 0) {
return undefined;
}
return searchResults;
});
}

View File

@@ -12,12 +12,6 @@ describe('requests the "/search" route', () => {
expect(response.json()).resolves.toMatchSnapshot();
});
it("valid query that returns amvstrm results", async () => {
const response = await app.request("/search?query=amvstrm");
expect(response.json()).resolves.toMatchSnapshot();
});
it("query that returns no results", async () => {
const response = await app.request("/search?query=a");

View File

@@ -3,7 +3,6 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
import { PaginatedResponseSchema } from "~/types/schema";
import { fetchSearchResultsFromAmvstrm } from "./amvstrm";
import { fetchSearchResultsFromAnilist } from "./anilist";
import { SearchResult } from "./searchResult";
@@ -41,7 +40,6 @@ app.openapi(route, async (c) => {
const { result: response, errorOccurred } = await fetchFromMultipleSources([
() => fetchSearchResultsFromAnilist(query, page, limit),
() => fetchSearchResultsFromAmvstrm(query, page, limit),
]);
if (!response) {