Fixed Message attachments!

This commit is contained in:
Raven Scott 2024-06-10 17:18:06 -04:00
parent 25e421e982
commit e1153cb5df

8
app.js
View File

@ -107,7 +107,7 @@ async function initialize() {
if (messageObj.type === 'icon') { if (messageObj.type === 'icon') {
const username = messageObj.username; const username = messageObj.username;
if (messageObj.avatar) { if (messageObj.avatar) {
const avatarBuffer = Buffer.from(messageObj.avatar, 'base64'); const avatarBuffer = b4a.from(messageObj.avatar, 'base64');
await drive.put(`/icons/${username}.png`, avatarBuffer); await drive.put(`/icons/${username}.png`, avatarBuffer);
updateIcon(username, avatarBuffer); updateIcon(username, avatarBuffer);
} else { } else {
@ -115,7 +115,7 @@ async function initialize() {
} }
} else if (messageObj.type === 'file') { } else if (messageObj.type === 'file') {
if (messageObj.file && messageObj.fileName) { if (messageObj.file && messageObj.fileName) {
const fileBuffer = Buffer.from(messageObj.file, 'base64'); const fileBuffer = b4a.from(messageObj.file, 'base64');
await drive.put(`/files/${messageObj.fileName}`, fileBuffer); await drive.put(`/files/${messageObj.fileName}`, fileBuffer);
const fileUrl = `http://localhost:${servePort}/files/${messageObj.fileName}`; const fileUrl = `http://localhost:${servePort}/files/${messageObj.fileName}`;
addFileMessage(messageObj.name, messageObj.fileName, updatePortInUrl(fileUrl), messageObj.fileType, updatePortInUrl(messageObj.avatar)); addFileMessage(messageObj.name, messageObj.fileName, updatePortInUrl(fileUrl), messageObj.fileType, updatePortInUrl(messageObj.avatar));
@ -140,7 +140,7 @@ async function initialize() {
const iconMessage = JSON.stringify({ const iconMessage = JSON.stringify({
type: 'icon', type: 'icon',
username: config.userName, username: config.userName,
avatar: iconBuffer.toString('base64'), avatar: b4a.toString(iconBuffer, 'base64'),
}); });
connection.write(iconMessage); connection.write(iconMessage);
} }
@ -339,7 +339,7 @@ async function handleFileInput(event) {
type: 'file', type: 'file',
name: config.userName, name: config.userName,
fileName: file.name, fileName: file.name,
file: buffer.toString('base64'), file: b4a.toString(buffer, 'base64'),
fileType: file.type, fileType: file.type,
avatar: updatePortInUrl(config.userAvatar), avatar: updatePortInUrl(config.userAvatar),
}; };