feat: add plant-it service

pull/2890/head
MDeLuise 4 months ago
parent 35af27f209
commit 3ec9127bfa

@ -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
```

@ -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

@ -825,5 +825,11 @@
"netdata": {
"warnings": "Warnings",
"criticals": "Criticals"
},
"plantit": {
"events": "Events",
"plants": "Plants",
"photos": "Photos",
"species": "Species"
}
}

@ -803,5 +803,11 @@
"netdata": {
"warnings": "Warnings",
"criticals": "Criticals"
},
"plantit": {
"events": "Eventi",
"plants": "Piante",
"species": "Specie",
"images": "Immagini"
}
}

@ -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}`;
}

@ -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")),

@ -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 <Container service={service} error={plantitError} />;
}
if (!plantitData) {
return (
<Container service={service}>
<Block label="plantit.events" />
<Block label="plantit.plants" />
<Block label="plantit.photos" />
<Block label="plantit.species" />
</Container>
);
}
return (
<Container service={service}>
<Block label="plantit.events" value={t("common.number", { value: plantitData.diaryEntryCount })} />
<Block label="plantit.plants" value={t("common.number", { value: plantitData.plantCount })} />
<Block label="plantit.photos" value={t("common.number", { value: plantitData.imageCount })} />
<Block label="plantit.species" value={t("common.number", { value: plantitData.botanicalInfoCount })} />
</Container>
);
}

@ -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;

@ -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,

Loading…
Cancel
Save