From 55d00260fa3de9595ee4e18dee2f4538335f9a94 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 05:09:39 -0400 Subject: [PATCH 01/11] fix user icons between peers --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 302e547..b975fe3 100644 --- a/app.js +++ b/app.js @@ -386,7 +386,7 @@ function onMessageAdded(from, message, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); - $img.src = avatar || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided + $img.src = updatePortInUrl(config.userAvatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided $img.classList.add('avatar'); $div.appendChild($img); From b46ca2b2df44dcc97e230c062453024d62c5542b Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 05:35:37 -0400 Subject: [PATCH 02/11] repair icons for report peers --- app.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index b975fe3..6f29bed 100644 --- a/app.js +++ b/app.js @@ -386,7 +386,9 @@ function onMessageAdded(from, message, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); - $img.src = updatePortInUrl(config.userAvatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided + + $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided + console.log(updatePortInUrl(avatar)) $img.classList.add('avatar'); $div.appendChild($img); From 3042974e55b942d572e05c68db24d724e6d0b903 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 05:40:37 -0400 Subject: [PATCH 03/11] repair file sharing hopefully --- app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 6f29bed..9626cc0 100644 --- a/app.js +++ b/app.js @@ -338,7 +338,7 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); - $img.src = avatar || 'https://via.placeholder.com/40'; + $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; $img.classList.add('avatar'); $div.appendChild($img); @@ -352,13 +352,13 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { if (fileType.startsWith('image/')) { const $image = document.createElement('img'); - $image.src = fileUrl; + $image.src = updatePortInUrl(fileUrl); $image.alt = fileName; $image.classList.add('attached-image'); $content.appendChild($image); } else { const $fileLink = document.createElement('a'); - $fileLink.href = fileUrl; + $fileLink.href = updatePortInUrl(fileUrl); $fileLink.textContent = `File: ${fileName}`; $fileLink.download = fileName; $content.appendChild($fileLink); From f6d9991c71f4623b64b2a7180ec47e9f486e0e13 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:06:08 -0400 Subject: [PATCH 04/11] attempts for file attachments again --- app.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 9626cc0..7d348fe 100644 --- a/app.js +++ b/app.js @@ -88,7 +88,7 @@ async function initialize() { const filePath = `/files/${file.name}`; await drive.put(filePath, buffer); const fileUrl = `http://localhost:${servePort}${filePath}`; - sendFileMessage(config.userName, fileUrl, file.type, config.userAvatar); + sendFileMessage(config.userName, filePath, file.type, config.userAvatar); // Send filePath instead of fileUrl }; reader.readAsArrayBuffer(file); } @@ -121,7 +121,9 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - addFileMessage(messageObj.name, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar); + const fileBuffer = await drive.get(messageObj.filePath); + const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: messageObj.fileType })); + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -313,13 +315,13 @@ function sendMessage(e) { } } -function sendFileMessage(name, fileUrl, fileType, avatar) { - const fileName = fileUrl.split('/').pop(); +async function sendFileMessage(name, filePath, fileType, avatar) { + const fileName = filePath.split('/').pop(); const messageObj = JSON.stringify({ type: 'file', name, fileName, - fileUrl, + filePath, fileType, avatar, timestamp: Date.now(), @@ -330,6 +332,8 @@ function sendFileMessage(name, fileUrl, fileType, avatar) { peer.write(messageObj); } + const fileBuffer = await drive.get(filePath); + const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: fileType })); addFileMessage(name, fileName, fileUrl, fileType, avatar); } @@ -352,13 +356,13 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { if (fileType.startsWith('image/')) { const $image = document.createElement('img'); - $image.src = updatePortInUrl(fileUrl); + $image.src = fileUrl; $image.alt = fileName; $image.classList.add('attached-image'); $content.appendChild($image); } else { const $fileLink = document.createElement('a'); - $fileLink.href = updatePortInUrl(fileUrl); + $fileLink.href = fileUrl; $fileLink.textContent = `File: ${fileName}`; $fileLink.download = fileName; $content.appendChild($fileLink); @@ -388,7 +392,6 @@ function onMessageAdded(from, message, avatar) { const $img = document.createElement('img'); $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided - console.log(updatePortInUrl(avatar)) $img.classList.add('avatar'); $div.appendChild($img); From b07579cdc9801433d272146e1b8eecc99ae85a23 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:10:42 -0400 Subject: [PATCH 05/11] another shot --- app.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 7d348fe..7cd574f 100644 --- a/app.js +++ b/app.js @@ -88,7 +88,7 @@ async function initialize() { const filePath = `/files/${file.name}`; await drive.put(filePath, buffer); const fileUrl = `http://localhost:${servePort}${filePath}`; - sendFileMessage(config.userName, filePath, file.type, config.userAvatar); // Send filePath instead of fileUrl + sendFileMessage(config.userName, fileUrl, file.type, config.userAvatar); }; reader.readAsArrayBuffer(file); } @@ -121,9 +121,7 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - const fileBuffer = await drive.get(messageObj.filePath); - const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: messageObj.fileType })); - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + addFileMessage(messageObj.name, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar); } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -315,13 +313,13 @@ function sendMessage(e) { } } -async function sendFileMessage(name, filePath, fileType, avatar) { - const fileName = filePath.split('/').pop(); +function sendFileMessage(name, fileUrl, fileType, avatar) { + const fileName = fileUrl.split('/').pop(); const messageObj = JSON.stringify({ type: 'file', name, fileName, - filePath, + fileUrl, fileType, avatar, timestamp: Date.now(), @@ -332,8 +330,6 @@ async function sendFileMessage(name, filePath, fileType, avatar) { peer.write(messageObj); } - const fileBuffer = await drive.get(filePath); - const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: fileType })); addFileMessage(name, fileName, fileUrl, fileType, avatar); } From 0010feed246fa90e7cc0e2c5207bfc9beed539c6 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:13:58 -0400 Subject: [PATCH 06/11] attempts for file attachments again --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 7cd574f..0300163 100644 --- a/app.js +++ b/app.js @@ -352,13 +352,13 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { if (fileType.startsWith('image/')) { const $image = document.createElement('img'); - $image.src = fileUrl; + $image.src = updatePortInUrl(fileUrl); $image.alt = fileName; $image.classList.add('attached-image'); $content.appendChild($image); } else { const $fileLink = document.createElement('a'); - $fileLink.href = fileUrl; + $fileLink.href = updatePortInUrl(fileUrl); $fileLink.textContent = `File: ${fileName}`; $fileLink.download = fileName; $content.appendChild($fileLink); From 206d095bcfc6f3de7d3253aeecd590e849947def Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:25:30 -0400 Subject: [PATCH 07/11] attempts for file attachments again --- app.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index 0300163..3319e8d 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,7 @@ import ServeDrive from 'serve-drive'; import Hyperdrive from 'hyperdrive'; import Corestore from 'corestore'; import { EventEmitter } from 'events'; -import fs from "fs"; +import fs from 'fs'; const storagePath = `./storage/`; const store = new Corestore(storagePath); @@ -88,7 +88,7 @@ async function initialize() { const filePath = `/files/${file.name}`; await drive.put(filePath, buffer); const fileUrl = `http://localhost:${servePort}${filePath}`; - sendFileMessage(config.userName, fileUrl, file.type, config.userAvatar); + sendFileMessage(config.userName, filePath, file.type, config.userAvatar); }; reader.readAsArrayBuffer(file); } @@ -121,7 +121,9 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - addFileMessage(messageObj.name, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar); + const fileBuffer = await drive.get(messageObj.filePath); + const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -313,13 +315,13 @@ function sendMessage(e) { } } -function sendFileMessage(name, fileUrl, fileType, avatar) { - const fileName = fileUrl.split('/').pop(); +function sendFileMessage(name, filePath, fileType, avatar) { + const fileName = filePath.split('/').pop(); const messageObj = JSON.stringify({ type: 'file', name, fileName, - fileUrl, + filePath, fileType, avatar, timestamp: Date.now(), @@ -330,6 +332,7 @@ function sendFileMessage(name, fileUrl, fileType, avatar) { peer.write(messageObj); } + const fileUrl = `http://localhost:${servePort}${filePath}`; addFileMessage(name, fileName, fileUrl, fileType, avatar); } @@ -377,7 +380,7 @@ function updatePeerCount() { } function scrollToBottom() { - var container = document.getElementById("messages-container"); + var container = document.getElementById('messages-container'); container.scrollTop = container.scrollHeight; } @@ -386,7 +389,6 @@ function onMessageAdded(from, message, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); - $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided $img.classList.add('avatar'); $div.appendChild($img); @@ -425,7 +427,7 @@ async function updateIcon(username, avatarBuffer) { userIcon.src = avatarUrl; config.userAvatar = avatarUrl; - writeConfigToFile("./config.json"); + writeConfigToFile('./config.json'); } } @@ -444,7 +446,7 @@ function toggleSetupView() { function writeConfigToFile(filePath) { fs.writeFile(filePath, JSON.stringify(config), (err) => { if (err) return console.error(err); - console.log("File has been created"); + console.log('File has been created'); }); } From 3835149c925457d6ca3c744b10806ddb2dea70d0 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:35:45 -0400 Subject: [PATCH 08/11] add debug --- app.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 3319e8d..cdf9e41 100644 --- a/app.js +++ b/app.js @@ -29,7 +29,7 @@ let config = { rooms: [] }; -// Function to get a random port between 1337 and 2223 +// Function to get a random port between 49152 and 65535 function getRandomPort() { return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152; } @@ -121,9 +121,17 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - const fileBuffer = await drive.get(messageObj.filePath); - const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + try { + const fileBuffer = await drive.get(messageObj.filePath); + if (fileBuffer) { + const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + } else { + console.error('File not found:', messageObj.filePath); + } + } catch (error) { + console.error('Error getting file:', error); + } } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -135,14 +143,18 @@ async function initialize() { console.log('Peer connected, current peer count:', peerCount); // Send the current user's icon to the new peer - const iconBuffer = await drive.get(`/icons/${config.userName}.png`); - if (iconBuffer) { - const iconMessage = JSON.stringify({ - type: 'icon', - username: config.userName, - avatar: iconBuffer.toString('base64'), - }); - connection.write(iconMessage); + try { + const iconBuffer = await drive.get(`/icons/${config.userName}.png`); + if (iconBuffer) { + const iconMessage = JSON.stringify({ + type: 'icon', + username: config.userName, + avatar: iconBuffer.toString('base64'), + }); + connection.write(iconMessage); + } + } catch (error) { + console.error('Error getting icon:', error); } connection.on('data', (data) => { From d5ea2abb7aa6653e269d0c07d63be8d4e25ffc4b Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:39:15 -0400 Subject: [PATCH 09/11] add debug --- app.js | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/app.js b/app.js index cdf9e41..9cded40 100644 --- a/app.js +++ b/app.js @@ -88,7 +88,7 @@ async function initialize() { const filePath = `/files/${file.name}`; await drive.put(filePath, buffer); const fileUrl = `http://localhost:${servePort}${filePath}`; - sendFileMessage(config.userName, filePath, file.type, config.userAvatar); + sendFileMessage(config.userName, filePath, file.type, config.userAvatar, buffer); }; reader.readAsArrayBuffer(file); } @@ -121,17 +121,10 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - try { - const fileBuffer = await drive.get(messageObj.filePath); - if (fileBuffer) { - const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); - } else { - console.error('File not found:', messageObj.filePath); - } - } catch (error) { - console.error('Error getting file:', error); - } + const fileBuffer = Buffer.from(messageObj.fileData, 'base64'); + await drive.put(messageObj.filePath, fileBuffer); + const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -143,18 +136,14 @@ async function initialize() { console.log('Peer connected, current peer count:', peerCount); // Send the current user's icon to the new peer - try { - const iconBuffer = await drive.get(`/icons/${config.userName}.png`); - if (iconBuffer) { - const iconMessage = JSON.stringify({ - type: 'icon', - username: config.userName, - avatar: iconBuffer.toString('base64'), - }); - connection.write(iconMessage); - } - } catch (error) { - console.error('Error getting icon:', error); + const iconBuffer = await drive.get(`/icons/${config.userName}.png`); + if (iconBuffer) { + const iconMessage = JSON.stringify({ + type: 'icon', + username: config.userName, + avatar: iconBuffer.toString('base64'), + }); + connection.write(iconMessage); } connection.on('data', (data) => { @@ -327,7 +316,7 @@ function sendMessage(e) { } } -function sendFileMessage(name, filePath, fileType, avatar) { +function sendFileMessage(name, filePath, fileType, avatar, fileBuffer) { const fileName = filePath.split('/').pop(); const messageObj = JSON.stringify({ type: 'file', @@ -336,6 +325,7 @@ function sendFileMessage(name, filePath, fileType, avatar) { filePath, fileType, avatar, + fileData: fileBuffer.toString('base64'), timestamp: Date.now(), }); From 5ff2460d239436cae71671539d30eab4c95cfe33 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:44:26 -0400 Subject: [PATCH 10/11] add debug, last try for now --- app.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 9cded40..9db7de8 100644 --- a/app.js +++ b/app.js @@ -121,10 +121,14 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - const fileBuffer = Buffer.from(messageObj.fileData, 'base64'); - await drive.put(messageObj.filePath, fileBuffer); - const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + try { + const fileBuffer = Buffer.from(messageObj.fileData, 'base64'); + await drive.put(messageObj.filePath, fileBuffer); + const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; + addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); + } catch (error) { + console.error('Error putting file:', error); + } } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } From f269781226aa72221820a5bdf0a84bcdd71d4490 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 07:00:42 -0400 Subject: [PATCH 11/11] revert too tired --- app.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 9db7de8..4a8545c 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,7 @@ import ServeDrive from 'serve-drive'; import Hyperdrive from 'hyperdrive'; import Corestore from 'corestore'; import { EventEmitter } from 'events'; -import fs from 'fs'; +import fs from "fs"; const storagePath = `./storage/`; const store = new Corestore(storagePath); @@ -29,7 +29,7 @@ let config = { rooms: [] }; -// Function to get a random port between 49152 and 65535 +// Function to get a random port between 1337 and 2223 function getRandomPort() { return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152; } @@ -88,7 +88,7 @@ async function initialize() { const filePath = `/files/${file.name}`; await drive.put(filePath, buffer); const fileUrl = `http://localhost:${servePort}${filePath}`; - sendFileMessage(config.userName, filePath, file.type, config.userAvatar, buffer); + sendFileMessage(config.userName, fileUrl, file.type, config.userAvatar); }; reader.readAsArrayBuffer(file); } @@ -121,14 +121,7 @@ async function initialize() { await drive.put(`/icons/${username}.png`, avatarBuffer); updateIcon(username, avatarBuffer); } else if (messageObj.type === 'file') { - try { - const fileBuffer = Buffer.from(messageObj.fileData, 'base64'); - await drive.put(messageObj.filePath, fileBuffer); - const fileUrl = `http://localhost:${servePort}${messageObj.filePath}`; - addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar); - } catch (error) { - console.error('Error putting file:', error); - } + addFileMessage(messageObj.name, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar); } else { onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar); } @@ -320,16 +313,15 @@ function sendMessage(e) { } } -function sendFileMessage(name, filePath, fileType, avatar, fileBuffer) { - const fileName = filePath.split('/').pop(); +function sendFileMessage(name, fileUrl, fileType, avatar) { + const fileName = fileUrl.split('/').pop(); const messageObj = JSON.stringify({ type: 'file', name, fileName, - filePath, + fileUrl, fileType, avatar, - fileData: fileBuffer.toString('base64'), timestamp: Date.now(), }); @@ -338,7 +330,6 @@ function sendFileMessage(name, filePath, fileType, avatar, fileBuffer) { peer.write(messageObj); } - const fileUrl = `http://localhost:${servePort}${filePath}`; addFileMessage(name, fileName, fileUrl, fileType, avatar); } @@ -347,7 +338,7 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); - $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; + $img.src = avatar || 'https://via.placeholder.com/40'; $img.classList.add('avatar'); $div.appendChild($img); @@ -361,13 +352,13 @@ function addFileMessage(from, fileName, fileUrl, fileType, avatar) { if (fileType.startsWith('image/')) { const $image = document.createElement('img'); - $image.src = updatePortInUrl(fileUrl); + $image.src = fileUrl; $image.alt = fileName; $image.classList.add('attached-image'); $content.appendChild($image); } else { const $fileLink = document.createElement('a'); - $fileLink.href = updatePortInUrl(fileUrl); + $fileLink.href = fileUrl; $fileLink.textContent = `File: ${fileName}`; $fileLink.download = fileName; $content.appendChild($fileLink); @@ -386,7 +377,7 @@ function updatePeerCount() { } function scrollToBottom() { - var container = document.getElementById('messages-container'); + var container = document.getElementById("messages-container"); container.scrollTop = container.scrollHeight; } @@ -395,7 +386,9 @@ function onMessageAdded(from, message, avatar) { $div.classList.add('message'); const $img = document.createElement('img'); + $img.src = updatePortInUrl(avatar) || 'https://via.placeholder.com/40'; // Default to a placeholder image if avatar URL is not provided + console.log(updatePortInUrl(avatar)) $img.classList.add('avatar'); $div.appendChild($img); @@ -433,7 +426,7 @@ async function updateIcon(username, avatarBuffer) { userIcon.src = avatarUrl; config.userAvatar = avatarUrl; - writeConfigToFile('./config.json'); + writeConfigToFile("./config.json"); } } @@ -452,7 +445,7 @@ function toggleSetupView() { function writeConfigToFile(filePath) { fs.writeFile(filePath, JSON.stringify(config), (err) => { if (err) return console.error(err); - console.log('File has been created'); + console.log("File has been created"); }); } @@ -463,4 +456,4 @@ function updatePortInUrl(url) { return urlObject.toString(); } -initialize(); +initialize(); \ No newline at end of file