feat: cancel "new episode" route early if no user is watching the title anymore

This commit is contained in:
2024-09-13 12:06:42 -04:00
parent 71799e4ae8
commit 45cc0cd36a
2 changed files with 17 additions and 1 deletions

View File

@@ -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<Env, typeof c>(c, "workerd"), aniListId))) {
console.log(`Title ${aniListId} is no longer being watched`);
return c.json(
{ success: true, result: { isNoLongerWatching: true } },
200,
);
}
const isAnifyEnabled = readEnvVariable<boolean>(
env<Env, typeof c>(c, "workerd"),
"ENABLE_ANIFY",