Calendar proxy handler

This commit is contained in:
shamoon 2023-11-24 23:29:38 -08:00
parent 184226d66f
commit c411c7da7a
5 changed files with 37 additions and 19 deletions

View File

@ -18,11 +18,9 @@ export default async function genericProxyHandler(req, res, map) {
} }
if (widget) { if (widget) {
const integration = widget?.integrations?.find((i) => i.name === endpoint) ?? {};
// if there are more than one question marks, replace others to & // if there are more than one question marks, replace others to &
const url = new URL( const url = new URL(
formatApiCall(widgets[widget.type].api, { endpoint, ...widget, ...integration }).replace(/(?<=\?.*)\?/g, "&"), formatApiCall(widgets[widget.type].api, { endpoint, ...widget }).replace(/(?<=\?.*)\?/g, "&"),
); );
const headers = req.extraHeaders ?? widget.headers ?? {}; const headers = req.extraHeaders ?? widget.headers ?? {};
@ -48,9 +46,6 @@ export default async function genericProxyHandler(req, res, map) {
} }
if (status === 200) { if (status === 200) {
if (integration?.url) {
return res.status(status).json({ data: resultData.toString() });
}
if (!validateWidgetData(widget, endpoint, resultData)) { if (!validateWidgetData(widget, endpoint, resultData)) {
return res return res
.status(status) .status(status)

View File

@ -0,0 +1,33 @@
import getServiceWidget from "utils/config/service-helpers";
import { httpProxy } from "utils/proxy/http";
import createLogger from "utils/logger";
const logger = createLogger("calendarProxyHandler");
export default async function calendarProxyHandler(req, res) {
const { group, service, endpoint } = req.query;
if (group && service) {
const widget = await getServiceWidget(group, service);
const integration = widget.integrations?.find((i) => i.name === endpoint);
if (integration) {
if (!integration.url) {
return res.status(403).json({ error: "No integration URL specified" });
}
const [status, contentType, data] = await httpProxy(integration.url);
if (contentType) res.setHeader("Content-Type", contentType);
if (status !== 200) {
logger.debug(`HTTTP ${status} retrieving data from integration URL ${integration.url} : ${data}`);
return res.status(status).send(data);
}
return res.status(status).json({ data: data.toString() });
}
}
return res.status(400).json({ error: "Invalid integration" });
}

View File

@ -1,8 +1,8 @@
import genericProxyHandler from "utils/proxy/handlers/generic"; import calendarProxyHandler from "./proxy";
const widget = { const widget = {
api: "{url}", api: "{url}",
proxyHandler: genericProxyHandler, proxyHandler: calendarProxyHandler,
}; };
export default widget; export default widget;

View File

@ -1,8 +0,0 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
const widget = {
api: "{url}",
proxyHandler: genericProxyHandler,
};
export default widget;

View File

@ -31,7 +31,6 @@ import hdhomerun from "./hdhomerun/widget";
import homeassistant from "./homeassistant/widget"; import homeassistant from "./homeassistant/widget";
import homebridge from "./homebridge/widget"; import homebridge from "./homebridge/widget";
import healthchecks from "./healthchecks/widget"; import healthchecks from "./healthchecks/widget";
import ical from "./ical/widget";
import immich from "./immich/widget"; import immich from "./immich/widget";
import jackett from "./jackett/widget"; import jackett from "./jackett/widget";
import jellyseerr from "./jellyseerr/widget"; import jellyseerr from "./jellyseerr/widget";
@ -113,7 +112,6 @@ const widgets = {
changedetectionio, changedetectionio,
channelsdvrserver, channelsdvrserver,
cloudflared, cloudflared,
calendar,
coinmarketcap, coinmarketcap,
customapi, customapi,
deluge, deluge,
@ -134,7 +132,7 @@ const widgets = {
homeassistant, homeassistant,
homebridge, homebridge,
healthchecks, healthchecks,
ical, ical: calendar,
immich, immich,
jackett, jackett,
jdownloader, jdownloader,