const $ = require('jquery'); const axios = require('axios'); const os = require('os'); // const remote = require('electron').remote; // const FindInPage = require('electron-find').FindInPage; // let findInPage = new FindInPage(remote.getCurrentWebContents()); // ipcRenderer.on('on-find', (e, args) => { // findInPage.openFindWindow(); // }); $('#loader').css('display', 'flex'); async function index() { try { const urlOkan = "https://io.okan.tools/api/auth/electron"; const token = 'HrZTvmBNyQaM6jPI7sHo5ywN35ht/cplIBFeE+4Ufx8='; const urlGetProfile = 'https://io.okan.tools/api/auth/users/electron'; let documento; let profile; try { const responseOkan = await axios.post(urlOkan, { user: process.env.USUARIO }, { headers: { 'Authorization': token } }); if (responseOkan.data.cod == '0') { ipcRenderer.send('newLog', { window: 'splash', log: 'Token obtenido: ' + responseOkan.data.data, msg: 'Información del documento encontrado...', splash: true }); console.log('Token: ' + responseOkan.data.data); const token_okan = 'Bearer ' + responseOkan.data.data; console.log(token_okan); try { const responseGetProfile = await axios.get(urlGetProfile, { headers: { 'Authorization': token_okan } }); if (responseGetProfile.data.cod == '0') { ipcRenderer.send('newLog', { window: 'splash', log: 'Perfil obtenido: ' + responseGetProfile.data.data.profile, msg: 'Información del documento encontrado...', splash: true }); console.log('Profile: ' + JSON.stringify(responseGetProfile.data.data)); documento = responseGetProfile.data.data.document_number; profile = responseGetProfile.data.data.profile.id; } else { ipcRenderer.send('newLog', { window: 'splash', log: 'Ha ocurrido un error: ' + responseGetProfile.data.message, msg: 'Ha ocurrido un error', splash: true }); } } catch (e) { ipcRenderer.send('newLog', { window: 'splash', log: 'Error al obtener el perfil: ' + e, msg: 'Error al obtener el perfil: '+e, splash: true }); } } else { ipcRenderer.send('newLog', { window: 'splash', log: 'Ha ocurrido un error: ' + responseGetProfile.data.message, msg: 'Ha ocurrido un error', splash: true }); } } catch (error) { ipcRenderer.send('newLog', { window: 'splash', log: 'Error al obtener el token: ' + error, msg: 'Error al obtener el token: '+error, splash: true }); } // const foundElement = datos.find(item => item.nickname === nicknameToFind); // if (foundElement) { // ipcRenderer.send('newLog', { window: 'splash', log: 'Usuario encontrado: ' + nicknameToFind, msg: 'Información del usuario encontrada...', splash: true }); // if (foundElement.document_number) { // documento = foundElement.document_number; // ipcRenderer.send('newLog', { window: 'splash', log: 'Documento encontrado: ' + documento, msg: 'Información del documento encontrado...', splash: true }); // } else { // ipcRenderer.send('newLog', { window: 'splash', log: 'Documento no encontrado', msg: 'No se pudo encontrar el documento del usuario...', splash: true }); // } // } else { // ipcRenderer.send('newLog', { window: 'splash', log: 'Usuario no encontrado', msg: 'No se pudo obtener el usuario...', splash: true }); // } // const urlProfile = `https://io.okan.tools/api/auth/user/${documento}`; // const responseProfile = await axios.get(urlProfile, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }); // if (responseProfile.data['cod'] == '0') { // profile = responseProfile.data['data']; // ipcRenderer.send('newLog', { window: 'splash', log: 'Perfil encontrado: ' + profile.profile.id, msg: 'Información del perfil encontrado...', splash: true }); // } const urlAplicativos = `https://adm.okan.tools/wp-json/okanapiwp/v1/aplicativos/${documento}/${profile}`; const responseAplicativos = await axios.get(urlAplicativos, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }); var apps_okan = []; var type_app; var url_service; var code_app; if (responseAplicativos.data['cod'] == '0') { const promises = responseAplicativos.data['data'].map(async element => { if (element['rpa'] == "true") { if (element['url'].includes('RpaClaro://?code=')) { var code_temp = element['url']; code_app = code_temp.slice(code_temp.indexOf("=") + 1); if(code_app != 'IRR123' && code_app != 'ACC098' && code_app != 'XLT001' && code_app != 'CTB002' && code_app != 'AVY003'){ url_service = "https://rpa.mind.brm.co/app"; type_app = 'apps'; } else { url_service = "https://rpa.mind.brm.co/desk"; type_app = 'desk'; } apps_okan.push( { 'code_app': code_app, 'name': element['nombre_app'], 'type_app': type_app, 'url_service': url_service, 'url_logo': element['logo'] }); } } }); } var status_integrado; var status; ipcRenderer.send('newLog', { window: 'splash', log: 'Aplicativos obtenidos: ' + apps_okan.length, msg: 'Obteniendo aplicaciones...', splash: true }); const promises = []; async function makeRequest(element) { try { const bodyContent = { code: element.code_app, user: process.env.USUARIO, }; console.log('_____________________________'); await axios.post(element.url_service, bodyContent, { headers: { "Accept": "*/*", "Content-Type": "application/json" } }) .then(response => { console.log(response.data); // Access the response data here status = response.data == 'Invalid parameter' ? false : true; console.log(status); status_integrado = status ? 'integrado' : 'no_integrado'; console.log(status_integrado); console.log('App: ' + element.code_app + ' - ' + status + ' - ' + element.name); $('#aplicativos').append(`