Save this

This commit is contained in:
shamoon 2024-09-14 23:07:51 -07:00
parent 85736c55c9
commit 27548fd3dc

View File

@ -57,25 +57,31 @@ export default async function piholeProxyHandler(req, res) {
} }
// pihole v6 // pihole v6
if (!cache.get(`${sessionSIDCacheKey}.${service}`)) { if (!cache.get(`${sessionSIDCacheKey}.${service}`) && widget.key) {
await login(widget, service); await login(widget, service);
} }
const sid = cache.get(`${sessionSIDCacheKey}.${service}`); const sid = cache.get(`${sessionSIDCacheKey}.${service}`);
if (!sid) { if (widget.key && !sid) {
return res.status(500).json({ error: "Failed to authenticate with Pi-hole" }); return res.status(500).json({ error: "Failed to authenticate with Pi-hole" });
} }
try { try {
logger.debug("Calling Pi-hole API endpoint: %s", endpoint); logger.debug("Calling Pi-hole API endpoint: %s", endpoint);
const headers = {
"Content-Type": "application/json",
};
if (sid) {
headers["X-FTL-SID"] = sid;
} else {
logger.debug("Pi-hole request is unauthenticated");
}
[status, , data] = await httpProxy(formatApiCall(widgets[widget.type].api, { ...widget, endpoint }), { [status, , data] = await httpProxy(formatApiCall(widgets[widget.type].api, { ...widget, endpoint }), {
headers: { headers,
"Content-Type": "application/json",
"X-FTL-SID": sid,
},
}); });
logger.debug("Pi-hole API response: %d", status, Buffer.from(data).toString("utf8"));
if (status !== 200) { if (status !== 200) {
logger.error("Error calling Pi-Hole API: %d. Data: %s", status, data); logger.error("Error calling Pi-Hole API: %d. Data: %s", status, data);
return res.status(status).json({ error: "Pi-Hole API Error", data }); return res.status(status).json({ error: "Pi-Hole API Error", data });