refactor: do title conversion server side
This commit is contained in:
@@ -41,7 +41,18 @@ export async function fetchSearchResultsFromAnilist(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { media: results, pageInfo } = page;
|
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) => {
|
.catch((err) => {
|
||||||
const response = err.response;
|
const response = err.response;
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
import { z } from "@hono/zod-openapi";
|
import { z } from "@hono/zod-openapi";
|
||||||
|
|
||||||
|
export type SearchResult = z.infer<typeof SearchResult>;
|
||||||
export const SearchResult = z.object({
|
export const SearchResult = z.object({
|
||||||
id: z.number().openapi({ type: "integer", format: "int64" }),
|
id: z.number().openapi({ type: "integer", format: "int64" }),
|
||||||
title: z.nullable(
|
title: z.nullable(z.string()),
|
||||||
z.object({
|
|
||||||
userPreferred: z.nullable(z.string()),
|
|
||||||
english: z.nullable(z.string()),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
coverImage: z.nullable(
|
coverImage: z.nullable(
|
||||||
z.object({
|
z.object({
|
||||||
medium: z.nullable(z.string()).optional(),
|
medium: z.nullable(z.string()).optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user