* feat(integrations): add ArchiveTeam Warrior widget * feat(integrations): add support for basic auth for archive warrior * refactor(integrations): address ArchiveTeam Warrior review feedback * Increase cache duration from 1 to 5 minutes --------- Co-authored-by: Manuel <30572287+manuel-rw@users.noreply.github.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { observable } from "@trpc/server/observable";
|
|
|
|
import type { ArchiveTeamWarriorStatus } from "@homarr/integrations";
|
|
import { archiveTeamWarriorRequestHandler } from "@homarr/request-handler/archive-team-warrior";
|
|
|
|
import { createOneIntegrationMiddleware } from "../../middlewares/integration";
|
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
|
|
|
export const archiveTeamWarriorRouter = createTRPCRouter({
|
|
getStatus: publicProcedure
|
|
.concat(createOneIntegrationMiddleware("query", "archiveTeamWarrior"))
|
|
.query(async ({ ctx }) => {
|
|
const handler = archiveTeamWarriorRequestHandler.handler(ctx.integration, {});
|
|
const { data, timestamp } = await handler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
|
|
return {
|
|
status: data,
|
|
updatedAt: timestamp,
|
|
};
|
|
}),
|
|
|
|
subscribeStatus: publicProcedure
|
|
.concat(createOneIntegrationMiddleware("query", "archiveTeamWarrior"))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{ status: ArchiveTeamWarriorStatus; updatedAt: Date }>((emit) => {
|
|
const handler = archiveTeamWarriorRequestHandler.handler(ctx.integration, {});
|
|
const unsubscribe = handler.subscribe((status) => {
|
|
emit.next({
|
|
status,
|
|
updatedAt: new Date(),
|
|
});
|
|
});
|
|
|
|
return () => {
|
|
unsubscribe();
|
|
};
|
|
});
|
|
}),
|
|
});
|