From db50bee0c7e8e7b606ee31303a4ffe1177405231 Mon Sep 17 00:00:00 2001 From: Jack Bailey <81699395+JackBailey@users.noreply.github.com> Date: Fri, 24 May 2024 19:09:22 +0100 Subject: [PATCH] Show disk usage and item count --- public/locales/en/common.json | 4 ++++ src/widgets/maintainerr/component.jsx | 20 +++++++++++++++----- src/widgets/maintainerr/widget.js | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 15de0ee9..e32df419 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -882,5 +882,9 @@ "enabled": "Enabled", "disabled": "Disabled", "total": "Total" + }, + "maintainerr": { + "usage": "Usage", + "items": "Items" } } diff --git a/src/widgets/maintainerr/component.jsx b/src/widgets/maintainerr/component.jsx index 363e0638..434cbba9 100644 --- a/src/widgets/maintainerr/component.jsx +++ b/src/widgets/maintainerr/component.jsx @@ -7,17 +7,16 @@ import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; - const { categoryId } = widget; - console.log({categoryId}); + const { collectionId } = widget; - const { data: collections, error: statsError } = useWidgetAPI(widget, "collections"); + const { data: collectionData, error: statsError } = useWidgetAPI(widget, "collection"); if (statsError) { return ; } - if (!collections) { + if (!collectionData) { return ( @@ -27,10 +26,21 @@ export default function Component({ service }) { ); } + + const totalSizes = collectionData.items.map((item) => { + const mediaSize = item.plexData.Media.map((media) => { + const totalPartSizes = media.Part.reduce((a, b) => a + b.size, 0) + return totalPartSizes + }).reduce((a, b) => a + b, 0) + return mediaSize + }).reduce((a, b) => a + b, 0); + + const items = collectionData.items.length; return ( - + + ); } diff --git a/src/widgets/maintainerr/widget.js b/src/widgets/maintainerr/widget.js index 951a5e8d..38976052 100644 --- a/src/widgets/maintainerr/widget.js +++ b/src/widgets/maintainerr/widget.js @@ -1,9 +1,13 @@ import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; -import { asJson, jsonArrayFilter } from "utils/proxy/api-helpers"; const widget = { api: "{url}/api/{endpoint}", proxyHandler: credentialedProxyHandler, + mappings: { + collection: { + endpoint: "collections/media/{collectionId}/content/1", + } + } }; export default widget;