From c078751561a7c81a8a94eee7138ca4d9b3ddaa88 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sat, 30 Nov 2024 02:26:30 -0500 Subject: [PATCH] small fix --- .env | 1 + app.js | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..38b1812 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +SERVER_KEY=0708bb56dd447a1b6951cc5b92522ab42994bd07d616375f4f0776df22b0b629 diff --git a/app.js b/app.js index fe80a88..a5afdf6 100644 --- a/app.js +++ b/app.js @@ -72,14 +72,39 @@ function deleteCookie(name) { // Load connections from cookies function loadConnections() { const savedConnections = getCookie('connections'); - return savedConnections ? JSON.parse(savedConnections) : {}; + const connections = savedConnections ? JSON.parse(savedConnections) : {}; + + // Recreate the topic Buffer from the hex string + for (const topicId in connections) { + const { topicHex } = connections[topicId]; + connections[topicId] = { + topic: b4a.from(topicHex, 'hex'), + topicHex, + peer: null, // Initialize additional properties + swarm: null, + }; + } + + return connections; } + // Save connections to cookies function saveConnections() { - setCookie('connections', JSON.stringify(connections)); + const serializableConnections = {}; + + for (const topicId in connections) { + const { topic, topicHex } = connections[topicId]; // Only serialize simple properties + serializableConnections[topicId] = { + topicHex, + topic: b4a.toString(topic, 'hex'), // Convert Buffer to hex string + }; + } + + setCookie('connections', JSON.stringify(serializableConnections)); } + // Add Reset Connections Button // Toggle Reset Connections Button Visibility function toggleResetButtonVisibility() { @@ -117,8 +142,14 @@ document.addEventListener('DOMContentLoaded', () => { // Restore saved connections Object.keys(savedConnections).forEach((topicId) => { - const topicHex = savedConnections[topicId].topicHex; - addConnection(topicHex); // Add connections using the saved topicHex + let topicHex = savedConnections[topicId].topic; + + // Ensure topicHex is a string + if (typeof topicHex !== 'string') { + topicHex = b4a.toString(topicHex, 'hex'); + } + + addConnection(topicHex); }); if (Object.keys(connections).length > 0) {