mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-01 04:09:12 +01:00
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import dayjs from "dayjs";
|
|
|
|
import type { IntegrationKindByCategory } from "@homarr/definitions";
|
|
import { createIntegrationAsync } from "@homarr/integrations";
|
|
import type { CalendarEvent, RadarrReleaseType } from "@homarr/integrations/types";
|
|
|
|
import { createCachedIntegrationRequestHandler } from "./lib/cached-integration-request-handler";
|
|
|
|
export const calendarMonthRequestHandler = createCachedIntegrationRequestHandler<
|
|
CalendarEvent[],
|
|
IntegrationKindByCategory<"calendar">,
|
|
{ year: number; month: number; releaseType: RadarrReleaseType[]; showUnmonitored: boolean }
|
|
>({
|
|
async requestAsync(integration, input) {
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
|
const startDate = dayjs().year(input.year).month(input.month).startOf("month");
|
|
const endDate = startDate.clone().endOf("month");
|
|
return await integrationInstance.getCalendarEventsAsync(
|
|
startDate.toDate(),
|
|
endDate.toDate(),
|
|
input.showUnmonitored,
|
|
);
|
|
},
|
|
cacheDuration: dayjs.duration(1, "minute"),
|
|
queryKey: "calendarMonth",
|
|
});
|