diff --git a/docs/widgets/services/planit.md b/docs/widgets/services/planit.md new file mode 100644 index 00000000..d29c70f1 --- /dev/null +++ b/docs/widgets/services/planit.md @@ -0,0 +1,13 @@ +--- +title: Plant-it +description: Plant-it Widget Configuration +--- + +API key can be created from the REST API. + +```yaml +widget: + type: plantit + url: http://plant-it.host.or.ip:port + key: plantit-api-key +``` diff --git a/mkdocs.yml b/mkdocs.yml index 572d36b4..f3376e4b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -67,6 +67,7 @@ nav: - widgets/services/homebridge.md - widgets/services/iframe.md - widgets/services/immich.md + - widgets/services/plantit.md - widgets/services/jackett.md - widgets/services/jdownloader.md - widgets/services/jellyfin.md diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 5521fd0c..cc6846a0 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -825,5 +825,11 @@ "netdata": { "warnings": "Warnings", "criticals": "Criticals" + }, + "plantit": { + "events": "Events", + "plants": "Plants", + "photos": "Photos", + "species": "Species" } } diff --git a/public/locales/it/common.json b/public/locales/it/common.json index 6f10baf7..e61fff8b 100644 --- a/public/locales/it/common.json +++ b/public/locales/it/common.json @@ -803,5 +803,11 @@ "netdata": { "warnings": "Warnings", "criticals": "Criticals" + }, + "plantit": { + "events": "Eventi", + "plants": "Piante", + "species": "Specie", + "images": "Immagini" } } diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 0795efd5..90b103af 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -61,6 +61,8 @@ export default async function credentialedProxyHandler(req, res, map) { headers.Authorization = `Basic ${Buffer.from(`$:${widget.key}`).toString("base64")}`; } else if (widget.type === "glances") { headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`; + } else if (widget.type === "plantit") { + headers.Key = `${widget.key}`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/components.js b/src/widgets/components.js index bb9b00fe..f9a0d11f 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -41,6 +41,7 @@ const components = { homebridge: dynamic(() => import("./homebridge/component")), healthchecks: dynamic(() => import("./healthchecks/component")), immich: dynamic(() => import("./immich/component")), + plantit: dynamic(() => import("./plantit/component")), jackett: dynamic(() => import("./jackett/component")), jdownloader: dynamic(() => import("./jdownloader/component")), jellyfin: dynamic(() => import("./emby/component")), diff --git a/src/widgets/plantit/component.jsx b/src/widgets/plantit/component.jsx new file mode 100644 index 00000000..ea203b87 --- /dev/null +++ b/src/widgets/plantit/component.jsx @@ -0,0 +1,37 @@ +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: plantitData, error: plantitError } = useWidgetAPI(widget, "plantit"); + + if (plantitError) { + return ; + } + + if (!plantitData) { + return ( + + + + + + + ); + } + + return ( + + + + + + + ); +} diff --git a/src/widgets/plantit/widget.js b/src/widgets/plantit/widget.js new file mode 100644 index 00000000..5a4bebc1 --- /dev/null +++ b/src/widgets/plantit/widget.js @@ -0,0 +1,21 @@ +import { asJson } from "utils/proxy/api-helpers"; +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "{url}/api/{endpoint}", + proxyHandler: credentialedProxyHandler, + + mappings: { + plantit: { + endpoint: "stats", + }, + map: (data) => ({ + events: Object.values(asJson(data).diaryEntryCount).reduce((acc, i) => acc + i, 0), + plants: Object.values(asJson(data).plantCount).reduce((acc, i) => acc + i, 0), + photos: Object.values(asJson(data).imageCount).reduce((acc, i) => acc + i, 0), + species: Object.values(asJson(data).botanicalInfoCount).reduce((acc, i) => acc + i, 0), + }), + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index fe474406..995beb39 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -34,6 +34,7 @@ import homeassistant from "./homeassistant/widget"; import homebridge from "./homebridge/widget"; import healthchecks from "./healthchecks/widget"; import immich from "./immich/widget"; +import plantit from "./plantit/widget"; import jackett from "./jackett/widget"; import jellyseerr from "./jellyseerr/widget"; import jdownloader from "./jdownloader/widget"; @@ -142,6 +143,7 @@ const widgets = { healthchecks, ical: calendar, immich, + plantit, jackett, jdownloader, jellyfin: emby,