Revert "Enhancement: encode uri params for synology proxy (#4414)"

This reverts commit 93c18a8077.

Revert "Fix synology param encoding"

This reverts commit bc3adf1f2a.

Revert "I think this will actually fix the synology handler"

This reverts commit 30fd42dba4.
pull/4439/head
shamoon 4 days ago
parent 30fd42dba4
commit d0eabf7adb

@ -8,14 +8,13 @@ import widgets from "widgets/widgets";
const INFO_ENDPOINT = "{url}/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query"; const INFO_ENDPOINT = "{url}/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query";
const AUTH_ENDPOINT = const AUTH_ENDPOINT =
"{url}/webapi/{path}?api=SYNO.API.Auth&version={maxVersion}&session=DownloadStation&format=cookie&method=login&{authParams}"; "{url}/webapi/{path}?api=SYNO.API.Auth&version={maxVersion}&method=login&account={username}&passwd={password}&session=DownloadStation&format=cookie";
const AUTH_API_NAME = "SYNO.API.Auth"; const AUTH_API_NAME = "SYNO.API.Auth";
const proxyName = "synologyProxyHandler"; const proxyName = "synologyProxyHandler";
const logger = createLogger(proxyName); const logger = createLogger(proxyName);
async function login(loginUrl) { async function login(loginUrl) {
logger.debug("Attempting login via %s", loginUrl);
const [status, contentType, data] = await httpProxy(loginUrl); const [status, contentType, data] = await httpProxy(loginUrl);
if (status !== 200) { if (status !== 200) {
return [status, contentType, data]; return [status, contentType, data];
@ -33,8 +32,8 @@ async function login(loginUrl) {
404 Failed to authenticate 2-step verification code 404 Failed to authenticate 2-step verification code
*/ */
let message = "Authentication failed."; let message = "Authentication failed.";
if (json?.error?.code && parseInt(json?.error?.code, 10) >= 403) message += " 2FA enabled."; if (json?.error?.code >= 403) message += " 2FA enabled.";
logger.error("Unable to login. Code: %d", json?.error?.code); logger.warn("Unable to login. Code: %d", json?.error?.code);
return [401, "application/json", JSON.stringify({ code: json?.error?.code, message })]; return [401, "application/json", JSON.stringify({ code: json?.error?.code, message })];
} }
@ -51,7 +50,6 @@ async function getApiInfo(serviceWidget, apiName, serviceName) {
const infoUrl = formatApiCall(INFO_ENDPOINT, serviceWidget); const infoUrl = formatApiCall(INFO_ENDPOINT, serviceWidget);
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const [status, contentType, data] = await httpProxy(infoUrl); const [status, contentType, data] = await httpProxy(infoUrl);
logger.debug("Received %d from Info endpoint %s", status, infoUrl);
if (status === 200) { if (status === 200) {
try { try {
@ -74,16 +72,12 @@ async function getApiInfo(serviceWidget, apiName, serviceName) {
} }
async function handleUnsuccessfulResponse(serviceWidget, url, serviceName) { async function handleUnsuccessfulResponse(serviceWidget, url, serviceName) {
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, serviceName); const [apiPath, maxVersion] = await getApiInfo(serviceWidget, AUTH_API_NAME, serviceName);
const authParams = new URLSearchParams({ account: serviceWidget.username, passwd: serviceWidget.password }); const authArgs = { path: apiPath ?? "entry.cgi", maxVersion: maxVersion ?? 7, ...serviceWidget };
const authArgs = {
path: apiPath ?? "entry.cgi",
maxVersion: maxVersion ?? 7,
url: serviceWidget.url,
authParams: authParams.toString(),
};
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);
@ -132,7 +126,7 @@ function toError(url, synologyError) {
error.error = synologyError.message ?? "Unknown error."; error.error = synologyError.message ?? "Unknown error.";
break; break;
} }
logger.error(`Unable to call ${url}. code: ${code}, error: ${error.error}.`); logger.warn(`Unable to call ${url}. code: ${code}, error: ${error.error}.`);
return error; return error;
} }
@ -160,7 +154,7 @@ export default async function synologyProxyHandler(req, res) {
apiMethod: mapping.apiMethod, apiMethod: mapping.apiMethod,
cgiPath, cgiPath,
maxVersion, maxVersion,
url: serviceWidget.url, ...serviceWidget,
}); });
let [status, contentType, data] = await httpProxy(url); let [status, contentType, data] = await httpProxy(url);
if (status !== 200) { if (status !== 200) {
@ -170,7 +164,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(`Request failed. Attempting login to ${serviceWidget.type}`); logger.debug(`Attempting login to ${serviceWidget.type}`);
[status, contentType, data] = await handleUnsuccessfulResponse(serviceWidget, url, service); [status, contentType, data] = await handleUnsuccessfulResponse(serviceWidget, url, service);
json = asJson(data); json = asJson(data);
} }

Loading…
Cancel
Save