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.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { Hono } from "hono";
|
|
import { DateTime } from "luxon";
|
|
|
|
import { getAdminSdkCredentials } from "~/libs/gcloud/getAdminSdkCredentials";
|
|
import { sendFcmMessage } from "~/libs/gcloud/sendFcmMessage";
|
|
import { SuccessResponse } from "~/types/schema";
|
|
|
|
import { getUpcomingTitlesFromAnilist } from "./anilist";
|
|
|
|
const app = new Hono();
|
|
|
|
app.post("/", async (c) => {
|
|
const titles = await getUpcomingTitlesFromAnilist(c.req);
|
|
|
|
await Promise.allSettled(
|
|
titles.map(async (title) => {
|
|
const titleName =
|
|
title.media.title?.userPreferred ??
|
|
title.media.title?.english ??
|
|
"Unknown Title";
|
|
|
|
return sendFcmMessage(getAdminSdkCredentials(), {
|
|
topic: "newTitles",
|
|
data: {
|
|
type: "new_title",
|
|
aniListId: title.media.id.toString(),
|
|
title: titleName,
|
|
airingAt: title.airingAt.toString(),
|
|
},
|
|
notification: {
|
|
title: "New Series Alert",
|
|
body: `${titleName} will be released ${DateTime.fromSeconds(title.airingAt).toRelative({ unit: ["hours", "minutes"] })}`,
|
|
image:
|
|
title.media.coverImage?.medium ??
|
|
title.media.coverImage?.large ??
|
|
title.media.coverImage?.extraLarge ??
|
|
undefined,
|
|
},
|
|
android: {
|
|
notification: {
|
|
click_action: "HANDLE_FCM_NOTIFICATION",
|
|
},
|
|
},
|
|
});
|
|
}),
|
|
);
|
|
|
|
return c.json(SuccessResponse, 200);
|
|
});
|
|
|
|
export default app;
|