feat: add user profile fetch in middleware
This commit is contained in:
@@ -2,6 +2,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
|
||||
import { fetchTitleFromAnilist } from "~/libs/anilist/getTitle";
|
||||
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
|
||||
import { userProfileMiddleware } from "~/middleware/userProfile";
|
||||
import {
|
||||
AniListIdQuerySchema,
|
||||
ErrorResponse,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
SuccessResponseSchema,
|
||||
} from "~/types/schema";
|
||||
import { Title } from "~/types/title";
|
||||
import type { User } from "~/types/user";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -40,6 +42,7 @@ const route = createRoute({
|
||||
description: "Title could not be found",
|
||||
},
|
||||
},
|
||||
middleware: [userProfileMiddleware],
|
||||
});
|
||||
|
||||
app.openapi(route, async (c) => {
|
||||
@@ -55,7 +58,12 @@ app.openapi(route, async (c) => {
|
||||
}
|
||||
|
||||
const { result: title, errorOccurred } = await fetchFromMultipleSources([
|
||||
() => fetchTitleFromAnilist(aniListId, aniListToken ?? undefined),
|
||||
() =>
|
||||
fetchTitleFromAnilist(
|
||||
aniListId,
|
||||
(c.get("user") as User)?.id,
|
||||
aniListToken ?? undefined,
|
||||
),
|
||||
]);
|
||||
|
||||
if (errorOccurred) {
|
||||
|
||||
Reference in New Issue
Block a user