refactor: do title conversion server side
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user