diff --git a/src/pages/api/services/proxy.js b/src/pages/api/services/proxy.js index 02214a637..fd39ab96a 100644 --- a/src/pages/api/services/proxy.js +++ b/src/pages/api/services/proxy.js @@ -41,6 +41,11 @@ export default async function handler(req, res) { const endpoint = mapping?.endpoint; const endpointProxy = mapping?.proxyHandler || serviceProxyHandler; + if (mapping.method && mapping.method !== req.method) { + logger.debug("Unsupported method: %s", req.method); + return res.status(403).json({ error: "Unsupported method" }); + } + if (!endpoint) { logger.debug("Unsupported service endpoint: %s", type); return res.status(403).json({ error: "Unsupported service endpoint" }); diff --git a/src/widgets/emby/component.jsx b/src/widgets/emby/component.jsx index 090a9c3f4..6f66d1dc4 100644 --- a/src/widgets/emby/component.jsx +++ b/src/widgets/emby/component.jsx @@ -225,7 +225,9 @@ export default function Component({ service }) { }), ); const url = `/api/services/proxy?${params.toString()}`; - await fetch(url).then(() => { + await fetch(url, { + method: "POST", + }).then(() => { sessionMutate(); }); } diff --git a/src/widgets/stash/component.jsx b/src/widgets/stash/component.jsx index 66f949c12..3d64c4902 100644 --- a/src/widgets/stash/component.jsx +++ b/src/widgets/stash/component.jsx @@ -1,18 +1,26 @@ import { useTranslation } from "next-i18next"; +import { useEffect, useState } from "react"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; -import useWidgetAPI from "utils/proxy/use-widget-api"; +import { formatProxyUrl } from "utils/proxy/api-helpers"; export default function Component({ service }) { const { t } = useTranslation(); const { widget } = service; - const { data: stats, error: stashError } = useWidgetAPI(widget, "stats"); + const [stats, setStats] = useState(null); - if (stashError) { - return ; - } + useEffect(() => { + async function fetchStats() { + const url = formatProxyUrl(widget, "stats"); + const res = await fetch(url, { method: "POST" }); + setStats(await res.json()); + } + if (!stats) { + fetchStats(); + } + }, [widget, stats]); if (!stats) { return ( diff --git a/src/widgets/unmanic/component.jsx b/src/widgets/unmanic/component.jsx index 03447068e..986884634 100644 --- a/src/widgets/unmanic/component.jsx +++ b/src/widgets/unmanic/component.jsx @@ -1,16 +1,30 @@ +import { useEffect, useState } from "react"; + import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +import { formatProxyUrl } from "utils/proxy/api-helpers"; export default function Component({ service }) { const { widget } = service; const { data: workersData, error: workersError } = useWidgetAPI(widget, "workers"); - const { data: pendingData, error: pendingError } = useWidgetAPI(widget, "pending"); - if (workersError || pendingError) { - const finalError = workersError ?? pendingError; - return ; + const [pendingData, setPendingData] = useState(null); + + useEffect(() => { + async function fetchPending() { + const url = formatProxyUrl(widget, "pending"); + const res = await fetch(url, { method: "POST" }); + setPendingData(await res.json()); + } + if (!pendingData) { + fetchPending(); + } + }, [widget, pendingData]); + + if (workersError) { + return ; } if (!workersData || !pendingData) { diff --git a/src/widgets/uptimerobot/component.jsx b/src/widgets/uptimerobot/component.jsx index c0cb670f3..274854019 100644 --- a/src/widgets/uptimerobot/component.jsx +++ b/src/widgets/uptimerobot/component.jsx @@ -1,18 +1,26 @@ import { useTranslation } from "next-i18next"; +import { useEffect, useState } from "react"; import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; -import useWidgetAPI from "utils/proxy/use-widget-api"; +import { formatProxyUrl } from "utils/proxy/api-helpers"; export default function Component({ service }) { const { widget } = service; const { t } = useTranslation(); - const { data: uptimerobotData, error: uptimerobotError } = useWidgetAPI(widget, "getmonitors"); + const [uptimerobotData, setUptimerobotData] = useState(null); - if (uptimerobotError) { - return ; - } + useEffect(() => { + async function fetchData() { + const url = formatProxyUrl(widget, "getmonitors"); + const res = await fetch(url, { method: "POST" }); + setUptimerobotData(await res.json()); + } + if (!uptimerobotData) { + fetchData(); + } + }, [widget, uptimerobotData]); if (!uptimerobotData) { return (