forked from snxraven/LinkUp-P2P-Chat
another shot
This commit is contained in:
parent
f6d9991c71
commit
b07579cdc9
14
app.js
14
app.js
@ -88,7 +88,7 @@ async function initialize() {
|
|||||||
const filePath = `/files/${file.name}`;
|
const filePath = `/files/${file.name}`;
|
||||||
await drive.put(filePath, buffer);
|
await drive.put(filePath, buffer);
|
||||||
const fileUrl = `http://localhost:${servePort}${filePath}`;
|
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);
|
reader.readAsArrayBuffer(file);
|
||||||
}
|
}
|
||||||
@ -121,9 +121,7 @@ async function initialize() {
|
|||||||
await drive.put(`/icons/${username}.png`, avatarBuffer);
|
await drive.put(`/icons/${username}.png`, avatarBuffer);
|
||||||
updateIcon(username, avatarBuffer);
|
updateIcon(username, avatarBuffer);
|
||||||
} else if (messageObj.type === 'file') {
|
} else if (messageObj.type === 'file') {
|
||||||
const fileBuffer = await drive.get(messageObj.filePath);
|
addFileMessage(messageObj.name, messageObj.fileName, messageObj.fileUrl, messageObj.fileType, messageObj.avatar);
|
||||||
const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: messageObj.fileType }));
|
|
||||||
addFileMessage(messageObj.name, messageObj.fileName, fileUrl, messageObj.fileType, messageObj.avatar);
|
|
||||||
} else {
|
} else {
|
||||||
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
|
onMessageAdded(messageObj.name, messageObj.message, messageObj.avatar);
|
||||||
}
|
}
|
||||||
@ -315,13 +313,13 @@ function sendMessage(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendFileMessage(name, filePath, fileType, avatar) {
|
function sendFileMessage(name, fileUrl, fileType, avatar) {
|
||||||
const fileName = filePath.split('/').pop();
|
const fileName = fileUrl.split('/').pop();
|
||||||
const messageObj = JSON.stringify({
|
const messageObj = JSON.stringify({
|
||||||
type: 'file',
|
type: 'file',
|
||||||
name,
|
name,
|
||||||
fileName,
|
fileName,
|
||||||
filePath,
|
fileUrl,
|
||||||
fileType,
|
fileType,
|
||||||
avatar,
|
avatar,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
@ -332,8 +330,6 @@ async function sendFileMessage(name, filePath, fileType, avatar) {
|
|||||||
peer.write(messageObj);
|
peer.write(messageObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileBuffer = await drive.get(filePath);
|
|
||||||
const fileUrl = URL.createObjectURL(new Blob([fileBuffer], { type: fileType }));
|
|
||||||
addFileMessage(name, fileName, fileUrl, fileType, avatar);
|
addFileMessage(name, fileName, fileUrl, fileType, avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user