|
|
@ -39,8 +39,8 @@ async function login(loginUrl) {
|
|
|
|
return [status, contentType, data];
|
|
|
|
return [status, contentType, data];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function getApiInfo(serviceWidget, apiName) {
|
|
|
|
async function getApiInfo(serviceWidget, apiName, serviceName) {
|
|
|
|
const cacheKey = `${proxyName}__${apiName}`;
|
|
|
|
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,11 +69,11 @@ 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);
|
|
|
@ -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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|