another shot

This commit is contained in:
Raven Scott 2024-06-09 06:10:42 -04:00
parent f6d9991c71
commit b07579cdc9

14
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); // 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);
}