Use credentialed proxy for miniflux

pull/631/head
Michael Shamoon 2 years ago
parent 3bef3dd6c6
commit 93445a2831

@ -36,6 +36,8 @@ export default async function credentialedProxyHandler(req, res, map) {
headers["X-API-Token"] = `${widget.key}`; headers["X-API-Token"] = `${widget.key}`;
} else if (widget.type === "tubearchivist") { } else if (widget.type === "tubearchivist") {
headers.Authorization = `Token ${widget.key}`; headers.Authorization = `Token ${widget.key}`;
} else if (widget.type === "miniflux") {
headers["X-Auth-Token"] = `${widget.key}`;
} else { } else {
headers["X-API-Key"] = `${widget.key}`; headers["X-API-Key"] = `${widget.key}`;
} }

@ -9,7 +9,7 @@ export default function Component({ service }) {
const { widget } = service; const { widget } = service;
const { data: minifluxData, error: minifluxError } = useWidgetAPI(widget); const { data: minifluxData, error: minifluxError } = useWidgetAPI(widget, "counters");
if (minifluxError) { if (minifluxError) {
return <Container error={minifluxError} />; return <Container error={minifluxError} />;

@ -1,45 +0,0 @@
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 });
}

@ -1,7 +1,19 @@
import minifluxProxyHandler from "./proxy"; import { asJson } from "utils/proxy/api-helpers";
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
const widget = { const widget = {
proxyHandler: minifluxProxyHandler, api: "{url}/v1/{endpoint}",
proxyHandler: credentialedProxyHandler,
mappings: {
counters: {
endpoint: "feeds/counters",
map: (data) => ({
read: Object.values(asJson(data).reads).reduce((acc, i) => acc + i, 0),
unread: Object.values(asJson(data).unreads).reduce((acc, i) => acc + i, 0)
}),
},
}
}; };
export default widget; export default widget;

Loading…
Cancel
Save