2024-11-23 17:16:44 +01:00
|
|
|
import dayjs from "dayjs";
|
|
|
|
|
|
|
|
|
|
import type { IntegrationKindByCategory } from "@homarr/definitions";
|
|
|
|
|
import type { StreamSession } from "@homarr/integrations";
|
2025-03-04 21:17:35 +01:00
|
|
|
import { createIntegrationAsync } from "@homarr/integrations";
|
2024-11-23 17:16:44 +01:00
|
|
|
|
|
|
|
|
import { createCachedIntegrationRequestHandler } from "./lib/cached-integration-request-handler";
|
|
|
|
|
|
|
|
|
|
export const mediaServerRequestHandler = createCachedIntegrationRequestHandler<
|
|
|
|
|
StreamSession[],
|
|
|
|
|
IntegrationKindByCategory<"mediaService">,
|
2025-04-22 18:30:46 +02:00
|
|
|
{
|
|
|
|
|
showOnlyPlaying: boolean;
|
|
|
|
|
}
|
2024-11-23 17:16:44 +01:00
|
|
|
>({
|
2025-04-22 18:30:46 +02:00
|
|
|
async requestAsync(integration, input) {
|
2025-03-04 21:17:35 +01:00
|
|
|
const integrationInstance = await createIntegrationAsync(integration);
|
2025-04-22 18:30:46 +02:00
|
|
|
return await integrationInstance.getCurrentSessionsAsync({ showOnlyPlaying: input.showOnlyPlaying });
|
2024-11-23 17:16:44 +01:00
|
|
|
},
|
|
|
|
|
cacheDuration: dayjs.duration(5, "seconds"),
|
|
|
|
|
queryKey: "mediaServerSessions",
|
|
|
|
|
});
|