Show disk usage and item count

This commit is contained in:
Jack Bailey 2024-05-24 19:09:22 +01:00
parent edaab688bb
commit db50bee0c7
No known key found for this signature in database
3 changed files with 24 additions and 6 deletions

View File

@ -882,5 +882,9 @@
"enabled": "Enabled", "enabled": "Enabled",
"disabled": "Disabled", "disabled": "Disabled",
"total": "Total" "total": "Total"
},
"maintainerr": {
"usage": "Usage",
"items": "Items"
} }
} }

View File

@ -7,17 +7,16 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) { export default function Component({ service }) {
const { t } = useTranslation(); const { t } = useTranslation();
const { widget } = service; 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) { if (statsError) {
return <Container service={service} error={statsError} />; return <Container service={service} error={statsError} />;
} }
if (!collections) { if (!collectionData) {
return ( return (
<Container service={service}> <Container service={service}>
<Block label="overseerr.pending" /> <Block label="overseerr.pending" />
@ -28,9 +27,20 @@ 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 ( return (
<Container service={service}> <Container service={service}>
<Block label="overseerr.pending" value={t("common.number", { value: collections.length })} /> <Block label="maintainerr.usage" value={t("common.bytes", { value: totalSizes })} />
<Block label="maintainerr.items" value={t("common.number", { value: items })} />
</Container> </Container>
); );
} }

View File

@ -1,9 +1,13 @@
import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
import { asJson, jsonArrayFilter } from "utils/proxy/api-helpers";
const widget = { const widget = {
api: "{url}/api/{endpoint}", api: "{url}/api/{endpoint}",
proxyHandler: credentialedProxyHandler, proxyHandler: credentialedProxyHandler,
mappings: {
collection: {
endpoint: "collections/media/{collectionId}/content/1",
}
}
}; };
export default widget; export default widget;