Add PhotoPrism widget
This commit is contained in:
parent
b96045eb8c
commit
551f521edd
6 changed files with 101 additions and 0 deletions
|
@ -465,5 +465,11 @@
|
|||
"series": "Series",
|
||||
"issues": "Issues",
|
||||
"wanted": "Wanted"
|
||||
},
|
||||
"photoprism": {
|
||||
"albums": "Albums",
|
||||
"photos": "Photos",
|
||||
"videos": "Videos",
|
||||
"people": "People"
|
||||
}
|
||||
}
|
|
@ -39,6 +39,7 @@ const components = {
|
|||
opnsense: dynamic(() => import("./opnsense/component")),
|
||||
overseerr: dynamic(() => import("./overseerr/component")),
|
||||
paperlessngx: dynamic(() => import("./paperlessngx/component")),
|
||||
photoprism: dynamic(() => import("./photoprism/component")),
|
||||
proxmoxbackupserver: dynamic(() => import("./proxmoxbackupserver/component")),
|
||||
pihole: dynamic(() => import("./pihole/component")),
|
||||
plex: dynamic(() => import("./plex/component")),
|
||||
|
|
37
src/widgets/photoprism/component.jsx
Normal file
37
src/widgets/photoprism/component.jsx
Normal file
|
@ -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: photoprismData, error: photoprismError } = useWidgetAPI(widget);
|
||||
|
||||
if (photoprismError) {
|
||||
return <Container error={photoprismError} />;
|
||||
}
|
||||
|
||||
if (!photoprismData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="photoprism.albums" />
|
||||
<Block label="photoprism.photos" />
|
||||
<Block label="photoprism.videos" />
|
||||
<Block label="photoprism.people" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="photoprism.albums" value={t("common.number", { value: photoprismData.albums + photoprismData.folders })} />
|
||||
<Block label="photoprism.photos" value={t("common.number", { value: photoprismData.photos })} />
|
||||
<Block label="photoprism.videos" value={t("common.number", { value: photoprismData.videos })} />
|
||||
<Block label="photoprism.people" value={t("common.number", { value: photoprismData.people })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
48
src/widgets/photoprism/proxy.js
Normal file
48
src/widgets/photoprism/proxy.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
|
||||
const logger = createLogger("photoprismProxyHandler");
|
||||
|
||||
export default async function photoprismProxyHandler(req, res) {
|
||||
const { group, service, endpoint } = req.query;
|
||||
|
||||
if (!group || !service) {
|
||||
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const widget = await getServiceWidget(group, service);
|
||||
|
||||
if (!widget) {
|
||||
logger.debug("Invalid or missing widget for service '%s' in group '%s'", service, group);
|
||||
return res.status(400).json({ error: "Invalid proxy service type" });
|
||||
}
|
||||
|
||||
const url = new URL(formatApiCall("{url}/api/v1/session", { endpoint, ...widget }));
|
||||
const params = {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: null
|
||||
};
|
||||
|
||||
if (widget.username && widget.password) {
|
||||
params.body = JSON.stringify({
|
||||
"username": widget.username,
|
||||
"password": widget.password
|
||||
});
|
||||
}
|
||||
|
||||
let [status, contentType, data] = await httpProxy(url, params);
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP %d getting data from PhotoPrism. Data: %s", status, data);
|
||||
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
|
||||
}
|
||||
|
||||
const json = JSON.parse(data.toString())
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(200).send(json?.config?.count);
|
||||
}
|
7
src/widgets/photoprism/widget.js
Normal file
7
src/widgets/photoprism/widget.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import photoprismProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
proxyHandler: photoprismProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -33,6 +33,7 @@ import ombi from "./ombi/widget";
|
|||
import opnsense from "./opnsense/widget";
|
||||
import overseerr from "./overseerr/widget";
|
||||
import paperlessngx from "./paperlessngx/widget";
|
||||
import photoprism from "./photoprism/widget";
|
||||
import proxmoxbackupserver from "./proxmoxbackupserver/widget";
|
||||
import pihole from "./pihole/widget";
|
||||
import plex from "./plex/widget";
|
||||
|
@ -99,6 +100,7 @@ const widgets = {
|
|||
opnsense,
|
||||
overseerr,
|
||||
paperlessngx,
|
||||
photoprism,
|
||||
proxmoxbackupserver,
|
||||
pihole,
|
||||
plex,
|
||||
|
|
Loading…
Add table
Reference in a new issue