Compare commits

..

5 Commits

Author SHA1 Message Date
28bb39474f docs: update README
add folder info about middleware
2025-12-18 23:47:28 -05:00
7cf0c4c1c7 feat: use luxon for TTL 2025-12-18 23:47:28 -05:00
45f6f678b6 chore: add debug logging to help understand why episode updates won't run 2025-12-18 23:47:27 -05:00
1958110679 chore: remove no longer needed isRetrying boolean 2025-12-18 23:43:11 -05:00
3294d3c6a2 fix: 'upcoming' titles failing to fetch
wasn't returning "Page" from the anilist json response
2025-12-18 23:43:10 -05:00
7 changed files with 16 additions and 35 deletions

View File

@@ -15,7 +15,7 @@ type AiringSchedule = {
id: number;
};
export async function getUpcomingTitlesFromAnilist() {
export async function getUpcomingTitlesFromAnilist(req: HonoRequest) {
const durableObjectId = env.ANILIST_DO.idFromName("GLOBAL");
const stub = env.ANILIST_DO.get(durableObjectId);

View File

@@ -9,8 +9,8 @@ import { getUpcomingTitlesFromAnilist } from "./anilist";
const app = new Hono();
export async function checkUpcomingTitles() {
const titles = await getUpcomingTitlesFromAnilist();
app.post("/", async (c) => {
const titles = await getUpcomingTitlesFromAnilist(c.req);
await Promise.allSettled(
titles.map(async (title) => {
@@ -44,10 +44,6 @@ export async function checkUpcomingTitles() {
});
}),
);
}
app.post("/", async (c) => {
await checkUpcomingTitles();
return c.json(SuccessResponse, 200);
});

View File

@@ -51,7 +51,7 @@ describe('requests the "/title" route', () => {
headers: new Headers({ "x-anilist-token": "asd" }),
});
await expect(response.json()).resolves.toMatchSnapshot();
expect(await response.json()).toMatchSnapshot();
expect(response.status).toBe(200);
});
@@ -63,7 +63,7 @@ describe('requests the "/title" route', () => {
const response = await app.request("/title?id=10");
await expect(response.json()).resolves.toMatchSnapshot();
expect(await response.json()).toMatchSnapshot();
expect(response.status).toBe(200);
});
@@ -75,7 +75,7 @@ describe('requests the "/title" route', () => {
const response = await app.request("/title?id=-1");
await expect(response.json()).resolves.toEqual({ success: false });
expect(await response.json()).toEqual({ success: false });
expect(response.status).toBe(404);
});
});

View File

@@ -12,8 +12,6 @@ import {
} from "~/libs/tasks/queueTask";
import { maybeUpdateLastConnectedAt } from "~/middleware/maybeUpdateLastConnectedAt";
import { checkUpcomingTitles } from "./controllers/internal/upcoming-titles";
export const app = new OpenAPIHono<{ Bindings: Env }>();
app.use(maybeUpdateLastConnectedAt);
@@ -123,20 +121,9 @@ export default {
});
},
async scheduled(event, env, ctx) {
switch (event.cron) {
case "0 */12 * * *":
const { processDelayedTasks } =
await import("~/libs/tasks/processDelayedTasks");
await processDelayedTasks(env);
break;
case "0 18 * * *":
const { checkUpcomingTitles } =
await import("~/controllers/internal/upcoming-titles");
await checkUpcomingTitles();
break;
default:
throw new Error(`Unhandled cron: ${event.cron}`);
}
const { processDelayedTasks } =
await import("~/libs/tasks/processDelayedTasks");
await processDelayedTasks(env);
},
} satisfies ExportedHandler<Env>;

View File

@@ -43,7 +43,7 @@ export class AnilistDurableObject extends DurableObject {
async getTitle(
id: number,
userId?: number,
userId?: string,
token?: string,
): Promise<Title | null> {
const promises: Promise<any>[] = [
@@ -135,7 +135,8 @@ export class AnilistDurableObject extends DurableObject {
nextSeason,
nextYear,
limit,
});
page,
}).then((data) => data?.Page);
},
DateTime.now().plus({ days: 1 }),
);
@@ -154,8 +155,7 @@ export class AnilistDurableObject extends DurableObject {
nextSeason,
nextYear,
limit,
page,
}).then((data) => data?.Page);
});
},
DateTime.now().plus({ days: 1 }),
);

View File

@@ -3,13 +3,11 @@ import mapKeys from "lodash.mapkeys";
import { Case, changeStringCase } from "../changeStringCase";
export function getAdminSdkCredentials(
env: Cloudflare.Env = cloudflareEnv,
): AdminSdkCredentials {
export function getAdminSdkCredentials(env: Cloudflare.Env = cloudflareEnv) {
return mapKeys(
JSON.parse(env.ADMIN_SDK_JSON) as AdminSdkCredentials,
(_, key) => changeStringCase(key, Case.snake_case, Case.camelCase),
) satisfies AdminSdkCredentials;
);
}
export interface AdminSdkCredentials {

View File

@@ -67,7 +67,7 @@ id = "c8db249d8ee7462b91f9c374321776e4"
preview_id = "ff38240eb2aa4b1388c705f4974f5aec"
[triggers]
crons = ["0 */12 * * *", "0 18 * * *"]
crons = ["0 */12 * * *"]
[[d1_databases]]
binding = "DB"