From 108753d01f1900c4b85371b1524e5e2674660799 Mon Sep 17 00:00:00 2001 From: Clairton Rodrigo Heinzen Date: Fri, 17 Jan 2025 08:18:17 -0300 Subject: [PATCH] fix remove session in ui --- package.json | 2 +- public/index.html | 38 ++++++++++++++++++---------------- src/services/client_baileys.ts | 2 +- src/services/socket.ts | 15 +++++++------- src/services/transformer.ts | 2 +- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index fc6318b..53d39e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unoapi-cloud", - "version": "1.25.0", + "version": "1.25.1", "description": "Unoapi Cloud", "exports": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/public/index.html b/public/index.html index a83e2ed..cce3fa8 100644 --- a/public/index.html +++ b/public/index.html @@ -474,7 +474,11 @@ } }); } + getSessionAndpopulateTable(token, hideForm) + } + // Populate Datatable with session numbers + function getSessionAndpopulateTable(token, hideForm) { const headers = { Authorization: `Bearer ${token}` }; fetch(apiUrl + '/sessions', { headers }) @@ -483,7 +487,6 @@ return response.json(); }) .then(resp => { - localStorage.setItem(tokenKey, token); if (hideForm) { $('#navbarDropdown').removeClass('d-none'); $('#login').addClass('d-none'); @@ -537,10 +540,9 @@ }) .then(response => { if (!response.ok) throw new Error("Erro no request."); - return response.json(); }) - .then(data => { - alert("A sessão foi removida!"); + .then(_ => { + alert("A sessão foi removida, recarrega a pagina para atualizar a lista!"); }) .catch(error => alert(error.message)); } @@ -824,26 +826,26 @@ // show number add modal function addInstance() { - const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal')); - addInstanceModal.show(); - } + const addInstanceModal = new bootstrap.Modal(document.getElementById('addInstanceModal')); + addInstanceModal.show(); + } - function submitInstanceNumber() { - const numberInput = document.getElementById('instanceNumber').value; + function submitInstanceNumber() { + const numberInput = document.getElementById('instanceNumber').value; - if (numberInput) { - const editModal = $('#editModal'); - editModal.data('number', numberInput); + if (numberInput) { + const editModal = $('#editModal'); + editModal.data('number', numberInput); - bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide(); + bootstrap.Modal.getInstance(document.getElementById('addInstanceModal')).hide(); - const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal')); - editInstanceModal.show(); + const editInstanceModal = new bootstrap.Modal(document.getElementById('editModal')); + editInstanceModal.show(); - } else { - alert('Por favor, insira um número válido.'); - } + } else { + alert('Por favor, insira um número válido.'); } + } diff --git a/src/services/client_baileys.ts b/src/services/client_baileys.ts index 2fdc2b8..7858543 100644 --- a/src/services/client_baileys.ts +++ b/src/services/client_baileys.ts @@ -351,9 +351,9 @@ export class ClientBaileys implements Client { async logout() { - await this.disconnect() logger.debug('Logout client store for %s', this?.phone) await this.socketLogout() + await this.disconnect() } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/services/socket.ts b/src/services/socket.ts index 7d8552f..f8ba9d2 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -331,17 +331,18 @@ export const connect = async ({ } const logout = async () => { - await close() - logger.info(`${phone} destroyed`) - await dataStore.cleanSession() - - logger.info(`${phone} disconnected`) - await sessionStore.setStatus(phone, 'disconnected') + logger.info(`${phone} logout`) try { return sock && await sock.logout() - } catch (_error) { + } catch (error) { + logger.error(`Error on remove session ${phone}: ${error.message}`,) // ignore de unique error if already diconected session + } finally { + await sessionStore.setStatus(phone, 'disconnected') + logger.info(`${phone} destroyed`) + await dataStore.cleanSession() } + await close() } const exists: exists = async (localPhone: string) => { diff --git a/src/services/transformer.ts b/src/services/transformer.ts index 9e09a75..52fbe31 100644 --- a/src/services/transformer.ts +++ b/src/services/transformer.ts @@ -606,7 +606,7 @@ export const fromBaileysMessageContent = (phone: string, payload: any, config?: case 'conversation': case 'extendedTextMessage': message.text = { - body: binMessage.text || binMessage, + body: binMessage?.text || binMessage, } message.type = 'text' break