mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 00:10:57 +00:00 
			
		
		
		
	Enhancement: encode uri params for synology proxy (#4414)
This commit is contained in:
		
							parent
							
								
									deff2f5506
								
							
						
					
					
						commit
						93c18a8077
					
				@ -6,9 +6,9 @@ import { httpProxy } from "utils/proxy/http";
 | 
			
		||||
import createLogger from "utils/logger";
 | 
			
		||||
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&{widgetParams}";
 | 
			
		||||
const AUTH_ENDPOINT =
 | 
			
		||||
  "{url}/webapi/{path}?api=SYNO.API.Auth&version={maxVersion}&method=login&account={username}&passwd={password}&session=DownloadStation&format=cookie";
 | 
			
		||||
  "{url}/webapi/{path}?api=SYNO.API.Auth&version={maxVersion}&session=DownloadStation&format=cookie&method=login&{widgetParams}";
 | 
			
		||||
const AUTH_API_NAME = "SYNO.API.Auth";
 | 
			
		||||
 | 
			
		||||
const proxyName = "synologyProxyHandler";
 | 
			
		||||
@ -47,7 +47,8 @@ async function getApiInfo(serviceWidget, apiName, serviceName) {
 | 
			
		||||
    return [cgiPath, maxVersion];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const infoUrl = formatApiCall(INFO_ENDPOINT, serviceWidget);
 | 
			
		||||
  const widgetParams = new URLSearchParams(serviceWidget);
 | 
			
		||||
  const infoUrl = formatApiCall(INFO_ENDPOINT, { widgetParams: widgetParams.toString() });
 | 
			
		||||
  // eslint-disable-next-line no-unused-vars
 | 
			
		||||
  const [status, contentType, data] = await httpProxy(infoUrl);
 | 
			
		||||
 | 
			
		||||
@ -77,7 +78,8 @@ async function handleUnsuccessfulResponse(serviceWidget, url, serviceName) {
 | 
			
		||||
  // eslint-disable-next-line no-unused-vars
 | 
			
		||||
  const [apiPath, maxVersion] = await getApiInfo(serviceWidget, AUTH_API_NAME, serviceName);
 | 
			
		||||
 | 
			
		||||
  const authArgs = { path: apiPath ?? "entry.cgi", maxVersion: maxVersion ?? 7, ...serviceWidget };
 | 
			
		||||
  const widgetParams = new URLSearchParams(serviceWidget);
 | 
			
		||||
  const authArgs = { path: apiPath ?? "entry.cgi", maxVersion: maxVersion ?? 7, widgetParams: widgetParams.toString() };
 | 
			
		||||
  const loginUrl = formatApiCall(AUTH_ENDPOINT, authArgs);
 | 
			
		||||
 | 
			
		||||
  const [status, contentType, data] = await login(loginUrl);
 | 
			
		||||
@ -149,12 +151,13 @@ export default async function synologyProxyHandler(req, res) {
 | 
			
		||||
    return res.status(400).json({ error: `Unrecognized API name: ${mapping.apiName}` });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const widgetParams = new URLSearchParams(serviceWidget);
 | 
			
		||||
  const url = formatApiCall(widget.api, {
 | 
			
		||||
    apiName: mapping.apiName,
 | 
			
		||||
    apiMethod: mapping.apiMethod,
 | 
			
		||||
    cgiPath,
 | 
			
		||||
    maxVersion,
 | 
			
		||||
    ...serviceWidget,
 | 
			
		||||
    widgetParams: widgetParams.toString(),
 | 
			
		||||
  });
 | 
			
		||||
  let [status, contentType, data] = await httpProxy(url);
 | 
			
		||||
  if (status !== 200) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user