From 4c17e3fd143714c8ad1acf3b6051145a3ae43a4c Mon Sep 17 00:00:00 2001 From: Benoit Date: Tue, 31 Jan 2023 12:07:23 +0100 Subject: [PATCH] Synology Widget : making it work with multiple widgets connecting to differents versions of DSM --- src/utils/proxy/handlers/synology.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/proxy/handlers/synology.js b/src/utils/proxy/handlers/synology.js index 3eab5df77..9895e113e 100644 --- a/src/utils/proxy/handlers/synology.js +++ b/src/utils/proxy/handlers/synology.js @@ -39,8 +39,8 @@ async function login(loginUrl) { 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) ?? {}; if (cgiPath && maxVersion) { return [cgiPath, maxVersion]; @@ -69,15 +69,15 @@ async function getApiInfo(serviceWidget, apiName) { return [null, null]; } -async function handleUnsuccessfulResponse(serviceWidget, url) { +async function handleUnsuccessfulResponse(serviceWidget, url, serviceName) { logger.debug(`Attempting login to ${serviceWidget.type}`); // 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 loginUrl = formatApiCall(AUTH_ENDPOINT, authArgs); - + const [status, contentType, data] = await login(loginUrl); if (status !== 200) { 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" }); } - const [cgiPath, maxVersion] = await getApiInfo(serviceWidget, mapping.apiName); + const [cgiPath, maxVersion] = await getApiInfo(serviceWidget, mapping.apiName, service); if (!cgiPath || !maxVersion) { 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); if (json?.success !== true) { 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); }