From b07579cdc9801433d272146e1b8eecc99ae85a23 Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Sun, 9 Jun 2024 06:10:42 -0400 Subject: [PATCH] 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); }