feat: cancel "new episode" route early if no user is watching the title anymore
This commit is contained in:
@@ -15,6 +15,7 @@ import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEp
|
|||||||
import { verifyQstashHeader } from "~/libs/qstash/verifyQstashHeader";
|
import { verifyQstashHeader } from "~/libs/qstash/verifyQstashHeader";
|
||||||
import { readEnvVariable } from "~/libs/readEnvVariable";
|
import { readEnvVariable } from "~/libs/readEnvVariable";
|
||||||
import { getTokensSubscribedToTitle } from "~/models/token";
|
import { getTokensSubscribedToTitle } from "~/models/token";
|
||||||
|
import { isWatchingTitle } from "~/models/watchStatus";
|
||||||
import type { Env } from "~/types/env";
|
import type { Env } from "~/types/env";
|
||||||
import type { EpisodesResponseSchema } from "~/types/episode";
|
import type { EpisodesResponseSchema } from "~/types/episode";
|
||||||
import type { FetchUrlResponse } from "~/types/episode/fetch-url-response";
|
import type { FetchUrlResponse } from "~/types/episode/fetch-url-response";
|
||||||
@@ -49,7 +50,14 @@ app.post(
|
|||||||
return c.json(ErrorResponse, { status: 401 });
|
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>(
|
const isAnifyEnabled = readEnvVariable<boolean>(
|
||||||
env<Env, typeof c>(c, "workerd"),
|
env<Env, typeof c>(c, "workerd"),
|
||||||
"ENABLE_ANIFY",
|
"ENABLE_ANIFY",
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user