add debug

This commit is contained in:
Raven Scott 2024-06-09 06:39:15 -04:00
parent 3835149c92
commit d5ea2abb7a

20
app.js
View File

@ -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 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 {
console.error('File not found:', messageObj.filePath);
}
} catch (error) {
console.error('Error getting file:', error);
}
} else {
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
}
@ -143,7 +136,6 @@ 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({
@ -153,9 +145,6 @@ async function initialize() {
});
connection.write(iconMessage);
}
} catch (error) {
console.error('Error getting icon:', error);
}
connection.on('data', (data) => {
const messageObj = JSON.parse(data.toString());
@ -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(),
});