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:
2025-08-10 19:22:14 -04:00
parent 0b0078328c
commit 8175d73df1
26 changed files with 8716 additions and 184 deletions

View File

@@ -1,12 +1,10 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { env } from "hono/adapter";
import { streamSSE } from "hono/streaming";
import { fetchEpisodes } from "~/controllers/episodes/getByAniListId";
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
import { associateDeviceIdWithUsername } from "~/models/token";
import { setWatchStatus } from "~/models/watchStatus";
import type { Env } from "~/types/env";
import { EpisodesResponseSchema } from "~/types/episode";
import { ErrorResponse, ErrorResponseSchema } from "~/types/schema";
import { Title } from "~/types/title";
@@ -87,7 +85,7 @@ const route = createRoute({
},
});
const app = new OpenAPIHono<Env>();
const app = new OpenAPIHono<Cloudflare.Env>();
app.openapi(route, async (c) => {
const deviceId =
@@ -112,11 +110,7 @@ app.openapi(route, async (c) => {
}
try {
await associateDeviceIdWithUsername(
env(c, "workerd"),
deviceId!,
user.name!,
);
await associateDeviceIdWithUsername(deviceId!, user.name!);
} catch (error) {
console.error("Failed to associate device");
console.error(error);
@@ -157,17 +151,12 @@ app.openapi(route, async (c) => {
const mediaListEntry = media.mediaListEntry;
if (mediaListEntry) {
const { wasAdded } = await setWatchStatus(
env(c, "workerd"),
deviceId!,
media.id,
mediaListEntry.status,
);
if (wasAdded) {
await maybeScheduleNextAiringEpisode(
env<Env, typeof c>(c, "workerd"),
c.req,
media.id,
);
await maybeScheduleNextAiringEpisode(c.req, media.id);
}
}