Feature: stash widget (#2238) (#2984)

This commit is contained in:
Zerebos 2024-02-23 09:02:11 -05:00 committed by shamoon
parent 45a9e2a6da
commit 8157b03380
7 changed files with 142 additions and 0 deletions

View file

@ -97,6 +97,7 @@ const components = {
scrutiny: dynamic(() => import("./scrutiny/component")),
sonarr: dynamic(() => import("./sonarr/component")),
speedtest: dynamic(() => import("./speedtest/component")),
stash: dynamic(() => import("./stash/component")),
strelaysrv: dynamic(() => import("./strelaysrv/component")),
tailscale: dynamic(() => import("./tailscale/component")),
tautulli: dynamic(() => import("./tautulli/component")),

View file

@ -0,0 +1,62 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: stats, error: stashError } = useWidgetAPI(widget, "stats");
if (stashError) {
return <Container service={service} error={stashError} />;
}
if (!stats) {
return (
<Container service={service}>
<Block label="stash.scenes" />
<Block label="stash.images" />
</Container>
);
}
// Provide a default if not set in the config
if (!widget.fields) {
widget.fields = ["scenes", "images"];
}
// Limit to a maximum of 4 at a time
if (widget.fields.length > 4) {
widget.fields = widget.fields.slice(0, 4);
}
return (
<Container service={service}>
<Block label="stash.scenes" value={t("common.number", { value: stats.scene_count })} />
<Block label="stash.scenesPlayed" value={t("common.number", { value: stats.scenes_played })} />
<Block label="stash.playCount" value={t("common.number", { value: stats.total_play_count })} />
<Block label="stash.playDuration" value={t("common.uptime", { value: stats.total_play_duration })} />
<Block
label="stash.sceneSize"
value={t("common.bbytes", { value: stats.scenes_size, maximumFractionDigits: 1 })}
/>
<Block label="stash.sceneDuration" value={t("common.uptime", { value: stats.scenes_duration })} />
<Block label="stash.images" value={t("common.number", { value: stats.image_count })} />
<Block
label="stash.imageSize"
value={t("common.bbytes", { value: stats.images_size, maximumFractionDigits: 1 })}
/>
<Block label="stash.galleries" value={t("common.number", { value: stats.gallery_count })} />
<Block label="stash.performers" value={t("common.number", { value: stats.performer_count })} />
<Block label="stash.studios" value={t("common.number", { value: stats.studio_count })} />
<Block label="stash.movies" value={t("common.number", { value: stats.movie_count })} />
<Block label="stash.tags" value={t("common.number", { value: stats.tag_count })} />
<Block label="stash.oCount" value={t("common.number", { value: stats.total_o_count })} />
</Container>
);
}

View file

@ -0,0 +1,40 @@
import { asJson } from "utils/proxy/api-helpers";
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}/{endpoint}?apikey={key}",
proxyHandler: genericProxyHandler,
mappings: {
stats: {
method: "POST",
endpoint: "graphql",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
query: `{
stats {
scene_count
scenes_size
scenes_duration
image_count
images_size
gallery_count
performer_count
studio_count
movie_count
tag_count
total_o_count
total_play_duration
total_play_count
scenes_played
}
}`,
}),
map: (data) => asJson(data).data.stats,
},
},
};
export default widget;

View file

@ -89,6 +89,7 @@ import sabnzbd from "./sabnzbd/widget";
import scrutiny from "./scrutiny/widget";
import sonarr from "./sonarr/widget";
import speedtest from "./speedtest/widget";
import stash from "./stash/widget";
import strelaysrv from "./strelaysrv/widget";
import tailscale from "./tailscale/widget";
import tautulli from "./tautulli/widget";
@ -201,6 +202,7 @@ const widgets = {
scrutiny,
sonarr,
speedtest,
stash,
strelaysrv,
tailscale,
tautulli,