mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-03 16:01:00 +00:00 
			
		
		
		
	Merge pull request #1519 from theshaun/main
QNAP plugin, fix key expiry issue
This commit is contained in:
		
						commit
						6046f7911e
					
				@ -57,8 +57,23 @@ async function apiCall(widget, endpoint, service) {
 | 
				
			|||||||
    return { status, contentType, data: null, responseHeaders };
 | 
					    return { status, contentType, data: null, responseHeaders };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const dataDecoded = xml2json(data.toString(), { compact: true });
 | 
					  let dataDecoded = JSON.parse(xml2json(data.toString(), { compact: true }).toString());
 | 
				
			||||||
  return { status, contentType, data: JSON.parse(dataDecoded.toString()), responseHeaders };
 | 
					
 | 
				
			||||||
 | 
					  if (dataDecoded.QDocRoot.authPassed._cdata === '0') {
 | 
				
			||||||
 | 
					    logger.error("QNAP API rejected the request, attempting to obtain new session token");
 | 
				
			||||||
 | 
					    key = await login(widget, service);
 | 
				
			||||||
 | 
					    apiUrl = new URL(formatApiCall(`${endpoint}&sid=${key}`, widget));
 | 
				
			||||||
 | 
					    [status, contentType, data, responseHeaders] = await httpProxy(apiUrl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (status !== 200) {
 | 
				
			||||||
 | 
					      logger.error("Error getting data from QNAP: %s status %d. Data: %s", apiUrl, status, data);
 | 
				
			||||||
 | 
					      return { status, contentType, data: null, responseHeaders };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    dataDecoded = JSON.parse(xml2json(data.toString(), { compact: true }).toString());
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return { status, contentType, data: dataDecoded, responseHeaders };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function qnapProxyHandler(req, res) {
 | 
					export default async function qnapProxyHandler(req, res) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user