Run pre-commit hooks over existing codebase

Co-Authored-By: Ben Phelps <ben@phelps.io>
This commit is contained in:
shamoon
2023-10-17 23:26:55 -07:00
parent fa50bbad9c
commit 19c25713c4
387 changed files with 4785 additions and 4109 deletions

View File

@@ -15,9 +15,10 @@ const logger = createLogger(proxyName);
async function getWidget(req) {
const { group, service, type } = req.query;
let widget = null;
if (type === "unifi_console") { // info widget
if (type === "unifi_console") {
// info widget
const index = req.query?.query ? JSON.parse(req.query.query).index : undefined;
widget = await getPrivateWidgetOptions(type, index);
if (!widget) {
@@ -30,7 +31,7 @@ async function getWidget(req) {
logger.debug("Invalid or missing service '%s' or group '%s'", service, group);
return null;
}
widget = await getServiceWidget(group, service);
if (!widget) {
@@ -43,7 +44,7 @@ async function getWidget(req) {
}
async function login(widget, csrfToken) {
const endpoint = (widget.prefix === udmpPrefix) ? "auth/login" : "login";
const endpoint = widget.prefix === udmpPrefix ? "auth/login" : "login";
const api = widgets?.[widget.type]?.api?.replace("{prefix}", ""); // no prefix for login url
const loginUrl = new URL(formatApiCall(api, { endpoint, ...widget }));
const loginBody = { username: widget.username, password: widget.password, remember: true };
@@ -93,9 +94,9 @@ export default async function unifiProxyHandler(req, res) {
setCookieHeader(url, params);
[status, contentType, data, responseHeaders] = await httpProxy(url, params);
if (status === 401) {
logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login.");
logger.debug("Unifi isn't logged in or rejected the reqeust, attempting login.");
if (responseHeaders?.["x-csrf-token"]) {
csrfToken = responseHeaders["x-csrf-token"];
}
@@ -103,7 +104,7 @@ export default async function unifiProxyHandler(req, res) {
if (status !== 200) {
logger.error("HTTP %d logging in to Unifi. Data: %s", status, data);
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
return res.status(status).json({ error: { message: `HTTP Error ${status}`, url, data } });
}
const json = JSON.parse(data.toString());
@@ -121,7 +122,7 @@ export default async function unifiProxyHandler(req, res) {
if (status !== 200) {
logger.error("HTTP %d getting data from Unifi endpoint %s. Data: %s", status, url.href, data);
return res.status(status).json({error: {message: `HTTP Error ${status}`, url, data}});
return res.status(status).json({ error: { message: `HTTP Error ${status}`, url, data } });
}
if (contentType) res.setHeader("Content-Type", contentType);