feat: miniflux widget

pull/631/head
Heng-Yi Wu 2 years ago committed by Michael Shamoon
parent db46931246
commit 3bef3dd6c6

@ -246,6 +246,10 @@
"status_count": "Posts",
"domain_count": "Domains"
},
"miniflux": {
"read": "Read",
"unread": "Unread"
},
"authentik": {
"users": "Users",
"loginsLast24H": "Logins (24h)",

@ -21,6 +21,7 @@ const components = {
jellyseerr: dynamic(() => import("./jellyseerr/component")),
lidarr: dynamic(() => import("./lidarr/component")),
mastodon: dynamic(() => import("./mastodon/component")),
miniflux: dynamic(() => import("./miniflux/component")),
navidrome: dynamic(() => import("./navidrome/component")),
npm: dynamic(() => import("./npm/component")),
nzbget: dynamic(() => import("./nzbget/component")),

@ -0,0 +1,33 @@
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: minifluxData, error: minifluxError } = useWidgetAPI(widget);
if (minifluxError) {
return <Container error={minifluxError} />;
}
if (!minifluxData) {
return (
<Container service={service}>
<Block label="miniflux.unread" />
<Block label="miniflux.read" />
</Container>
);
}
return (
<Container service={service}>
<Block label="miniflux.unread" value={t("common.number", { value: minifluxData.unread })} />
<Block label="miniflux.read" value={t("common.number", { value: minifluxData.read })} />
</Container>
);
}

@ -0,0 +1,45 @@
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("minifluxProxyHandler");
export default async function minifluxProxyHandler(req, res) {
const { group, service } = 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}/v1/feeds/counters", { ...widget }));
url.username = widget.username;
url.password = widget.password;
const params = {
method: "GET",
headers: {
"X-Auth-Token": widget.token
}
};
// eslint-disable-next-line no-unused-vars
const [status, contentType, data] = await httpProxy(url, params);
let read = 0;
let unread = 0;
if (status === 200) {
const parsed = JSON.parse(data.toString());
read = Object.values(parsed.reads).reduce((acc, i) => acc + i, 0);
unread = Object.values(parsed.unreads).reduce((acc, i) => acc + i, 0);
}
return res.status(status).send({ read, unread });
}

@ -0,0 +1,7 @@
import minifluxProxyHandler from "./proxy";
const widget = {
proxyHandler: minifluxProxyHandler,
};
export default widget;

@ -16,6 +16,7 @@ import jackett from "./jackett/widget";
import jellyseerr from "./jellyseerr/widget";
import lidarr from "./lidarr/widget";
import mastodon from "./mastodon/widget";
import miniflux from "./miniflux/widget";
import navidrome from "./navidrome/widget";
import npm from "./npm/widget";
import nzbget from "./nzbget/widget";
@ -66,6 +67,7 @@ const widgets = {
jellyseerr,
lidarr,
mastodon,
miniflux,
navidrome,
npm,
nzbget,

Loading…
Cancel
Save