refactor: do title conversion server side

This commit is contained in:
2024-10-27 09:27:27 -04:00
parent 2ec61b7332
commit 99963083f0
2 changed files with 14 additions and 7 deletions

View File

@@ -41,7 +41,18 @@ export async function fetchSearchResultsFromAnilist(
}
const { media: results, pageInfo } = page;
return { results, hasNextPage: pageInfo?.hasNextPage };
return {
results: results?.map((result) => {
if (!result) return null;
return {
id: result.id,
title: result.title?.userPreferred ?? result.title?.english,
coverImage: result.coverImage,
};
}),
hasNextPage: pageInfo?.hasNextPage,
};
})
.catch((err) => {
const response = err.response;

View File

@@ -1,13 +1,9 @@
import { z } from "@hono/zod-openapi";
export type SearchResult = z.infer<typeof SearchResult>;
export const SearchResult = z.object({
id: z.number().openapi({ type: "integer", format: "int64" }),
title: z.nullable(
z.object({
userPreferred: z.nullable(z.string()),
english: z.nullable(z.string()),
}),
),
title: z.nullable(z.string()),
coverImage: z.nullable(
z.object({
medium: z.nullable(z.string()).optional(),