mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
Basic widget data validation
This commit is contained in:
parent
5b7d2eaf07
commit
7b7740563e
6 changed files with 88 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
import getServiceWidget from "utils/config/service-helpers";
|
||||
import { formatApiCall } from "utils/proxy/api-helpers";
|
||||
import validateWidgetData from "utils/proxy/validate-widget-data";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
import createLogger from "utils/logger";
|
||||
import widgets from "widgets/widgets";
|
||||
|
@ -32,6 +33,11 @@ export default async function genericProxyHandler(req, res, map) {
|
|||
});
|
||||
|
||||
let resultData = data;
|
||||
|
||||
if (!validateWidgetData(widget, endpoint, resultData)) {
|
||||
return res.status(status).json({error: {message: "Invalid data", url, data: resultData}});
|
||||
}
|
||||
|
||||
if (status === 200 && map) {
|
||||
resultData = map(data);
|
||||
}
|
||||
|
@ -44,6 +50,7 @@ export default async function genericProxyHandler(req, res, map) {
|
|||
|
||||
if (status >= 400) {
|
||||
logger.debug("HTTP Error %d calling %s//%s%s...", status, url.protocol, url.hostname, url.pathname);
|
||||
return res.status(status).json({error: {message: "HTTP Error", url, data}});
|
||||
}
|
||||
|
||||
return res.status(status).send(resultData);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue