Explorar o código

Synology Widget : making it work with multiple widgets connecting to differents versions of DSM

Benoit %!s(int64=2) %!d(string=hai) anos
pai
achega
4c17e3fd14
Modificáronse 1 ficheiros con 7 adicións e 7 borrados
  1. 7 7
      src/utils/proxy/handlers/synology.js

+ 7 - 7
src/utils/proxy/handlers/synology.js

@@ -39,8 +39,8 @@ async function login(loginUrl) {
   return [status, contentType, data];
   return [status, contentType, data];
 }
 }
 
 
-async function getApiInfo(serviceWidget, apiName) {
-  const cacheKey = `${proxyName}__${apiName}`;
+async function getApiInfo(serviceWidget, apiName, serviceName) {
+  const cacheKey = `${proxyName}__${apiName}__${serviceName}`
   let { cgiPath, maxVersion } = cache.get(cacheKey) ?? {};
   let { cgiPath, maxVersion } = cache.get(cacheKey) ?? {};
   if (cgiPath && maxVersion) {
   if (cgiPath && maxVersion) {
     return [cgiPath, maxVersion];
     return [cgiPath, maxVersion];
@@ -69,15 +69,15 @@ async function getApiInfo(serviceWidget, apiName) {
   return [null, null];
   return [null, null];
 }
 }
 
 
-async function handleUnsuccessfulResponse(serviceWidget, url) {
+async function handleUnsuccessfulResponse(serviceWidget, url, serviceName) {
   logger.debug(`Attempting login to ${serviceWidget.type}`);
   logger.debug(`Attempting login to ${serviceWidget.type}`);
 
 
   // eslint-disable-next-line no-unused-vars
   // eslint-disable-next-line no-unused-vars
-  const [apiPath, maxVersion] = await getApiInfo(serviceWidget, AUTH_API_NAME);
+  const [apiPath, maxVersion] = await getApiInfo(serviceWidget, AUTH_API_NAME, serviceName);
 
 
   const authArgs = { path: apiPath ?? "entry.cgi", maxVersion: maxVersion ?? 7, ...serviceWidget };
   const authArgs = { path: apiPath ?? "entry.cgi", maxVersion: maxVersion ?? 7, ...serviceWidget };
   const loginUrl = formatApiCall(AUTH_ENDPOINT, authArgs);
   const loginUrl = formatApiCall(AUTH_ENDPOINT, authArgs);
-  
+
   const [status, contentType, data] = await login(loginUrl);
   const [status, contentType, data] = await login(loginUrl);
   if (status !== 200) {
   if (status !== 200) {
     return [status, contentType, data];
     return [status, contentType, data];
@@ -142,7 +142,7 @@ export default async function synologyProxyHandler(req, res) {
     return res.status(403).json({ error: "Service does not support API calls" });
     return res.status(403).json({ error: "Service does not support API calls" });
   }
   }
 
 
-  const [cgiPath, maxVersion] = await getApiInfo(serviceWidget, mapping.apiName);
+  const [cgiPath, maxVersion] = await getApiInfo(serviceWidget, mapping.apiName, service);
   if (!cgiPath || !maxVersion) {
   if (!cgiPath || !maxVersion) {
     return res.status(400).json({ error: `Unrecognized API name: ${mapping.apiName}`})
     return res.status(400).json({ error: `Unrecognized API name: ${mapping.apiName}`})
   }
   }
@@ -163,7 +163,7 @@ export default async function synologyProxyHandler(req, res) {
   let json = asJson(data);
   let json = asJson(data);
   if (json?.success !== true) {
   if (json?.success !== true) {
     logger.debug(`Attempting login to ${serviceWidget.type}`);
     logger.debug(`Attempting login to ${serviceWidget.type}`);
-    [status, contentType, data] = await handleUnsuccessfulResponse(serviceWidget, url);
+    [status, contentType, data] = await handleUnsuccessfulResponse(serviceWidget, url, service);
     json = asJson(data);
     json = asJson(data);
   }
   }