mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-12 12:02:09 +08:00
Feature: Jellystat widget (#5185)
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Some checks failed
Crowdin Action / Crowdin Sync (push) Has been cancelled
Docker CI / Linting Checks (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Repository Maintenance / Stale (push) Has been cancelled
Repository Maintenance / Lock Old Threads (push) Has been cancelled
Repository Maintenance / Close Answered Discussions (push) Has been cancelled
Repository Maintenance / Close Outdated Discussions (push) Has been cancelled
Repository Maintenance / Close Unsupported Feature Requests (push) Has been cancelled
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
38
src/widgets/jellystat/component.jsx
Normal file
38
src/widgets/jellystat/component.jsx
Normal file
@@ -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>
|
||||
);
|
||||
}
|
||||
15
src/widgets/jellystat/widget.js
Normal file
15
src/widgets/jellystat/widget.js
Normal file
@@ -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