refactor: ♻️emoves Env parameter
Removes the `Env` parameter from several functions to simplify their signatures and rely on the global `env` for configuration. This change reduces the number of arguments passed around, making the code cleaner and easier to maintain.
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import type { HonoRequest } from "hono";
|
||||
import { env } from "hono/adapter";
|
||||
|
||||
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
|
||||
import { buildNewEpisodeTaskId } from "~/libs/tasks/id";
|
||||
import { queueTask } from "~/libs/tasks/queueTask";
|
||||
import { removeTask } from "~/libs/tasks/removeTask";
|
||||
import { setWatchStatus } from "~/models/watchStatus";
|
||||
import type { Env } from "~/types/env";
|
||||
import {
|
||||
AniListIdSchema,
|
||||
ErrorResponse,
|
||||
@@ -19,7 +17,7 @@ import { WatchStatus } from "~/types/title/watchStatus";
|
||||
|
||||
import { maybeUpdateWatchStatusOnAnilist } from "./anilist";
|
||||
|
||||
const app = new OpenAPIHono<Env>();
|
||||
const app = new OpenAPIHono<Cloudflare.Env>();
|
||||
|
||||
const UpdateWatchStatusRequest = z.object({
|
||||
deviceId: z.string(),
|
||||
@@ -67,22 +65,20 @@ const route = createRoute({
|
||||
});
|
||||
|
||||
export async function updateWatchStatus(
|
||||
env: Env,
|
||||
req: HonoRequest,
|
||||
deviceId: string,
|
||||
titleId: number,
|
||||
watchStatus: WatchStatus | null,
|
||||
) {
|
||||
const { wasAdded, wasDeleted } = await setWatchStatus(
|
||||
env,
|
||||
deviceId,
|
||||
Number(titleId),
|
||||
watchStatus,
|
||||
);
|
||||
if (wasAdded) {
|
||||
await maybeScheduleNextAiringEpisode(env, req, titleId);
|
||||
await maybeScheduleNextAiringEpisode(req, titleId);
|
||||
} else if (wasDeleted) {
|
||||
await removeTask(env, "new-episode", buildNewEpisodeTaskId(titleId));
|
||||
await removeTask("new-episode", buildNewEpisodeTaskId(titleId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,13 +93,7 @@ app.openapi(route, async (c) => {
|
||||
|
||||
if (!isRetrying) {
|
||||
try {
|
||||
await updateWatchStatus(
|
||||
env(c, "workerd"),
|
||||
c.req,
|
||||
deviceId,
|
||||
titleId,
|
||||
watchStatus,
|
||||
);
|
||||
await updateWatchStatus(c.req, deviceId, titleId, watchStatus);
|
||||
} catch (error) {
|
||||
console.error("Error setting watch status");
|
||||
console.error(error);
|
||||
@@ -125,7 +115,6 @@ app.openapi(route, async (c) => {
|
||||
}
|
||||
|
||||
await queueTask(
|
||||
env(c, "workerd"),
|
||||
"anilist-updates",
|
||||
{
|
||||
deviceId,
|
||||
|
||||
Reference in New Issue
Block a user