diff --git a/src/controllers/internal/new-episode/index.ts b/src/controllers/internal/new-episode/index.ts index 58770d4..4a5f605 100644 --- a/src/controllers/internal/new-episode/index.ts +++ b/src/controllers/internal/new-episode/index.ts @@ -15,6 +15,7 @@ import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEp import { verifyQstashHeader } from "~/libs/qstash/verifyQstashHeader"; import { readEnvVariable } from "~/libs/readEnvVariable"; import { getTokensSubscribedToTitle } from "~/models/token"; +import { isWatchingTitle } from "~/models/watchStatus"; import type { Env } from "~/types/env"; import type { EpisodesResponseSchema } from "~/types/episode"; import type { FetchUrlResponse } from "~/types/episode/fetch-url-response"; @@ -49,7 +50,14 @@ app.post( return c.json(ErrorResponse, { status: 401 }); } - const domain = getCurrentDomain(c.req); + if (!(await isWatchingTitle(env(c, "workerd"), aniListId))) { + console.log(`Title ${aniListId} is no longer being watched`); + return c.json( + { success: true, result: { isNoLongerWatching: true } }, + 200, + ); + } + const isAnifyEnabled = readEnvVariable( env(c, "workerd"), "ENABLE_ANIFY", diff --git a/src/models/watchStatus.ts b/src/models/watchStatus.ts index d6b60ee..d5b55dc 100644 --- a/src/models/watchStatus.ts +++ b/src/models/watchStatus.ts @@ -57,3 +57,11 @@ function removeTitle(env: Env, deviceId: string, titleId: number) { ), ); } + +export function isWatchingTitle(env: Env, titleId: number) { + return getDb(env) + .select() + .from(watchStatusTable) + .where(eq(watchStatusTable.titleId, titleId)) + .then((results) => results.length > 0); +}