mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-30 16:01:17 -07:00
Feature: Jellystat widget (#5185)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Block from "components/services/widget/block";
|
||||
import Container from "components/services/widget/container";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { widget } = service;
|
||||
|
||||
// Days validation
|
||||
if (!(Number.isInteger(widget.days) && 0 < widget.days)) widget.days = 30;
|
||||
|
||||
const { data: viewsData, error: viewsError } = useWidgetAPI(widget, "getViewsByLibraryType", { days: widget.days });
|
||||
|
||||
const error = viewsError || viewsData?.message;
|
||||
if (error) {
|
||||
return <Container service={service} error={error} />;
|
||||
}
|
||||
|
||||
if (!viewsData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="jellystat.songs" />
|
||||
<Block label="jellystat.movies" />
|
||||
<Block label="jellystat.episodes" />
|
||||
<Block label="jellystat.other" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="jellystat.songs" value={viewsData.Audio} />
|
||||
<Block label="jellystat.movies" value={viewsData.Movie} />
|
||||
<Block label="jellystat.episodes" value={viewsData.Series} />
|
||||
<Block label="jellystat.other" value={viewsData.Other} />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
getViewsByLibraryType: {
|
||||
endpoint: "stats/getViewsByLibraryType",
|
||||
params: ["days"],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
||||
Reference in New Issue
Block a user