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

@@ -4,14 +4,12 @@ import { PromiseTimedOutError, promiseTimeout } from "~/libs/promiseTimeout";
import { readEnvVariable } from "~/libs/readEnvVariable";
import { sortByProperty } from "~/libs/sortByProperty";
import { getValue, setValue } from "~/models/kv";
import type { Env } from "~/types/env";
import type { EpisodesResponse } from "~/types/episode";
export async function getEpisodesFromAnify(
env: Env,
aniListId: number,
): Promise<EpisodesResponse | null> {
if (await shouldSkipAnify(env, aniListId)) {
if (await shouldSkipAnify(aniListId)) {
console.log("Skipping Anify for title", aniListId);
return null;
}
@@ -33,7 +31,6 @@ export async function getEpisodesFromAnify(
DateTime.now().plus({ minutes: 1 }).toISO(),
);
setValue(
env,
"anify_killswitch_till",
DateTime.now().plus({ minutes: 1 }).toISO(),
);
@@ -93,11 +90,8 @@ export async function getEpisodesFromAnify(
};
}
export async function shouldSkipAnify(
env: Env,
aniListId: number,
): Promise<boolean> {
if (!readEnvVariable(env, "ENABLE_ANIFY")) {
export async function shouldSkipAnify(aniListId: number): Promise<boolean> {
if (!readEnvVariable("ENABLE_ANIFY")) {
return true;
}
@@ -114,7 +108,7 @@ export async function shouldSkipAnify(
return true;
}
return await getValue(env, "anify_killswitch_till").then((dateTime) => {
return await getValue("anify_killswitch_till").then((dateTime) => {
if (!dateTime) {
return false;
}

View File

@@ -1,6 +1,5 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import type { Env } from "~/types/env";
import { EpisodesResponseSchema } from "~/types/episode";
import {
AniListIdQuerySchema,
@@ -37,7 +36,7 @@ const route = createRoute({
},
});
const app = new OpenAPIHono<Env>();
const app = new OpenAPIHono<Cloudflare.Env>();
export function fetchEpisodes(aniListId: number, shouldRetry: boolean = false) {
return import("./aniwatch")

View File

@@ -1,6 +1,5 @@
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import type { Env } from "~/types/env";
import { FetchUrlResponse } from "~/types/episode/fetch-url-response";
import {
AniListIdQuerySchema,
@@ -65,7 +64,7 @@ const route = createRoute({
},
});
const app = new OpenAPIHono<Env>();
const app = new OpenAPIHono<Cloudflare.Env>();
export async function fetchEpisodeUrl({
id,

View File

@@ -2,7 +2,6 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
import { env } from "hono/adapter";
import { updateWatchStatus } from "~/controllers/watch-status";
import type { Env } from "~/types/env";
import {
AniListIdQuerySchema,
EpisodeNumberSchema,
@@ -63,7 +62,7 @@ const route = createRoute({
},
});
const app = new OpenAPIHono<Env>();
const app = new OpenAPIHono<Cloudflare.Env>();
app.openapi(route, async (c) => {
const aniListToken = c.req.header("X-AniList-Token");
@@ -85,13 +84,7 @@ app.openapi(route, async (c) => {
isComplete,
);
if (isComplete) {
await updateWatchStatus(
env(c, "workerd"),
c.req,
deviceId,
aniListId,
"COMPLETED",
);
await updateWatchStatus(c.req, deviceId, aniListId, "COMPLETED");
}
if (!user) {