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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user