瀏覽代碼

remove unnecessary watchtower header cache, code style

Michael Shamoon 2 年之前
父節點
當前提交
5f71486b74
共有 2 個文件被更改,包括 10 次插入20 次删除
  1. 9 19
      src/widgets/watchtower/proxy.js
  2. 1 1
      src/widgets/watchtower/widget.js

+ 9 - 19
src/widgets/watchtower/proxy.js

@@ -1,5 +1,3 @@
-import cache from "memory-cache";
-
 import { httpProxy } from "utils/proxy/http";
 import { httpProxy } from "utils/proxy/http";
 import { formatApiCall } from "utils/proxy/api-helpers";
 import { formatApiCall } from "utils/proxy/api-helpers";
 import getServiceWidget from "utils/config/service-helpers";
 import getServiceWidget from "utils/config/service-helpers";
@@ -7,7 +5,6 @@ import createLogger from "utils/logger";
 import widgets from "widgets/widgets";
 import widgets from "widgets/widgets";
 
 
 const proxyName = "watchtowerProxyHandler";
 const proxyName = "watchtowerProxyHandler";
-const headerCacheKey = `${proxyName}__headers`;
 const logger = createLogger(proxyName);
 const logger = createLogger(proxyName);
 
 
 export default async function watchtowerProxyHandler(req, res) {
 export default async function watchtowerProxyHandler(req, res) {
@@ -25,34 +22,27 @@ export default async function watchtowerProxyHandler(req, res) {
     return res.status(400).json({ error: "Invalid proxy service type" });
     return res.status(400).json({ error: "Invalid proxy service type" });
   }
   }
 
 
-  let headers = cache.get(headerCacheKey);
-  if (!headers) {
-    headers = {
-      "Authorization": `Bearer ${widget.key}`,
-    }
-    cache.put(headerCacheKey, headers);
-  }
-
   const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));  
   const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget }));  
   
   
-  const method = "GET"
   const [status, contentType, data] = await httpProxy(url, {
   const [status, contentType, data] = await httpProxy(url, {
-    method,
-    headers,
+    method: "GET",
+    headers: {
+      "Authorization": `Bearer ${widget.key}`,
+    }
   });
   });
 
 
+  if (status !== 200 || !data) {
+    logger.error("Error getting data from WatchTower: %d.  Data: %s", status, data);
+  }
+
   const cleanData = data.toString().split("\n").filter(s => s.startsWith("watchtower"))
   const cleanData = data.toString().split("\n").filter(s => s.startsWith("watchtower"))
-  const jsonRes={}
+  const jsonRes = {}
   
   
   cleanData.map(e => e.split(" ")).forEach(strArray => { 
   cleanData.map(e => e.split(" ")).forEach(strArray => { 
     const [key, value] = strArray
     const [key, value] = strArray
     jsonRes[key] = value
     jsonRes[key] = value
   }) 
   }) 
 
 
-  if (status !== 200) {
-    logger.error("Error getting data from WatchTower: %d.  Data: %s", status, data);
-  }
-
   if (contentType) res.setHeader("Content-Type", contentType);
   if (contentType) res.setHeader("Content-Type", contentType);
   return res.status(status).send(jsonRes);
   return res.status(status).send(jsonRes);
 }
 }

+ 1 - 1
src/widgets/watchtower/widget.js

@@ -11,4 +11,4 @@ const widget = {
   },
   },
 };
 };
 
 
-export default widget;
+export default widget;