parent
3bef3dd6c6
commit
93445a2831
@ -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…
Reference in new issue