commit
cb3c20ecbd
@ -0,0 +1,42 @@
|
||||
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: tdarrData, error: tdarrError } = useWidgetAPI(widget);
|
||||
|
||||
if (tdarrError) {
|
||||
return <Container error={tdarrError} />;
|
||||
}
|
||||
|
||||
if (!tdarrData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="tdarr.queue" />
|
||||
<Block label="tdarr.processed" />
|
||||
<Block label="tdarr.errored" />
|
||||
<Block label="tdarr.saved" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const queue = parseInt(tdarrData.table1Count, 10) + parseInt(tdarrData.table4Count, 10);
|
||||
const processed = parseInt(tdarrData.table2Count, 10) + parseInt(tdarrData.table5Count, 10);
|
||||
const errored = parseInt(tdarrData.table3Count, 10) + parseInt(tdarrData.table6Count, 10);
|
||||
const saved = parseFloat(tdarrData.sizeDiff, 10) * 1000000000;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="tdarr.queue" value={t("common.number", { value: queue })} />
|
||||
<Block label="tdarr.processed" value={t("common.number", { value: processed })} />
|
||||
<Block label="tdarr.errored" value={t("common.number", { value: errored })} />
|
||||
<Block label="tdarr.saved" value={t("common.bytes", { value: saved })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import createLogger from "utils/logger";
|
||||
import widgets from "widgets/widgets";
|
||||
|
||||
const proxyName = "tdarrProxyHandler";
|
||||
const logger = createLogger(proxyName);
|
||||
|
||||
export default async function tdarrProxyHandler(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(widgets[widget.type].api, { endpoint, ...widget }));
|
||||
|
||||
const [status, contentType, data] = await httpProxy(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"data": {
|
||||
"collection": "StatisticsJSONDB",
|
||||
"mode": "getById",
|
||||
"docID": "statistics"
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("Error getting data from Tdarr: %d. Data: %s", status, data);
|
||||
return res.status(500).send({error: {message:"Error getting data from Tdarr", url, data}});
|
||||
}
|
||||
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
return res.status(status).send(data);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import tdarrProxyHandler from "./proxy";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/v2/cruddb",
|
||||
proxyHandler: tdarrProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Reference in new issue