import { ConnectionSettings , getHostUrl } from "../state" ; import { ClientRequestResult , SessionName , SynologyClient } from "./synology" ; export async function testConnection ( settings ) { const api = new SynologyClient ( { baseUrl : getHostUrl ( settings ) , account : settings . username , passwd : settings . password , session : SessionName . DownloadStation , } ) ; const loginResult = await api . Auth . Login ( { timeout : 30000 } ) ; if ( ! ClientRequestResult . isConnectionFailure ( loginResult ) && loginResult . success ) { api . Auth . Logout ( { timeout : 10000 } ) . then ( ( logoutResponse ) => { if ( logoutResponse === "not-logged-in" ) { console . error ( `wtf: not logged in immediately after successfully logging in` ) ; } else if ( ClientRequestResult . isConnectionFailure ( logoutResponse ) || ! logoutResponse . success ) { console . error ( "ignoring unexpected failure while logging out after successful connection test" , logoutResponse ) ; } } ) ; } return loginResult ; }