refactor: reduce verbosity and dead code across new integrations

- Remove dead widget.audiobookshelf/navidrome i18n blocks (76 lines)
- Simplify audio-stats router (remove duplicated kind casts)
- Remove redundant defaultDisplayOptions in audio-stats component
- Dedup fetch helpers in uptime-kuma (fetchOkAsync) and
  paperless-ngx (fetchAuthenticatedAsync)
- Simplify navidrome asArray helper and getArtistCountAsync
- Simplify uptime-kuma averageUptimePercent and status derivation
This commit is contained in:
Thomas Camlong committed 2026-06-09 21:28:02 +02:00
1 parent ad76ce9cdc
commit fe35a9cf68
6 files changed
+34 -173

No files matched your search

+8 -22
View File
@@ -1,40 +1,26 @@
import type { AudiobookshelfDashboardData, NavidromeDashboardData } from "@homarr/integrations/types";
import { audiobookshelfRequestHandler } from "@homarr/request-handler/audiobookshelf";
import { navidromeRequestHandler } from "@homarr/request-handler/navidrome";
import { createOneIntegrationMiddleware } from "../../middlewares/integration";
import { createTRPCRouter, publicProcedure } from "../../trpc";
const requestHandlerByKind = {
navidrome: navidromeRequestHandler,
audiobookshelf: audiobookshelfRequestHandler,
} as const;
export const audioStatsRouter = createTRPCRouter({
getStats: publicProcedure
.concat(createOneIntegrationMiddleware("query", "navidrome", "audiobookshelf"))
.query(async ({ ctx }) => {
const fetchStatsByKind = {
const { kind } = ctx.integration;
const fetchByKind = {
navidrome: async () => {
const navidromeIntegration = { ...ctx.integration, kind: "navidrome" as const };
const innerHandler = requestHandlerByKind.navidrome.handler(navidromeIntegration, {});
const data = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
return {
kind: "navidrome" as const,
data: data.data as NavidromeDashboardData,
};
const handler = navidromeRequestHandler.handler({ ...ctx.integration, kind: "navidrome" as const }, {});
return (await handler.getCachedOrUpdatedDataAsync({ forceUpdate: false })).data;
},
audiobookshelf: async () => {
const audiobookshelfIntegration = { ...ctx.integration, kind: "audiobookshelf" as const };
const innerHandler = requestHandlerByKind.audiobookshelf.handler(audiobookshelfIntegration, {});
const data = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
return {
kind: "audiobookshelf" as const,
data: data.data as AudiobookshelfDashboardData,
};
const handler = audiobookshelfRequestHandler.handler({ ...ctx.integration, kind: "audiobookshelf" as const }, {});
return (await handler.getCachedOrUpdatedDataAsync({ forceUpdate: false })).data;
},
} as const;
return fetchStatsByKind[ctx.integration.kind]();
return { kind, data: await fetchByKind[kind]() };
}),
});