mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
added tdarr widget
This commit is contained in:
committed by
Michael Shamoon
parent
e7b0fc1419
commit
aaa1f76176
58
src/widgets/tdarr/proxy.js
Normal file
58
src/widgets/tdarr/proxy.js
Normal file
@@ -0,0 +1,58 @@
|
||||
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 method = "POST";
|
||||
|
||||
const headers = {
|
||||
"content-type": "application/json",
|
||||
};
|
||||
|
||||
const body = JSON.stringify({
|
||||
"data": {
|
||||
"collection": "StatisticsJSONDB",
|
||||
"mode": "getById",
|
||||
"docID": "statistics"
|
||||
}
|
||||
});
|
||||
|
||||
let [status, contentType, data, responseHeaders] = await httpProxy(url, {
|
||||
method,
|
||||
body,
|
||||
headers,
|
||||
});
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user