LinkUp-P2P-Chat/chatBot/includes/message/FileMessage.js

30 lines
1018 B
JavaScript
Raw Normal View History

2024-06-14 09:43:17 -04:00
import Message from "./Message.js";
import b4a from "b4a";
2024-06-14 09:43:17 -04:00
class FileMessage extends Message {
constructor(peerName, peerAvatar, topic, timestamp, fileName, fileUrl, fileType, fileData) {
2024-06-14 09:43:17 -04:00
super("file", peerName, peerAvatar, topic, timestamp);
this.fileName = fileName;
this.fileUrl = fileUrl;
this.fileType = fileType;
this.fileData = fileData; // Add file data property
}
2024-06-11 17:40:02 -04:00
toJsonString() {
return JSON.stringify({
2024-06-14 09:43:17 -04:00
...this.toJson(),
fileName: this.fileName,
fileUrl: this.fileUrl,
fileType: this.fileType,
file: this.fileData // Include file data in JSON
});
}
2024-06-14 09:43:17 -04:00
static new(bot, fileName, fileUrl, fileType, fileBuffer) {
const fileData = b4a.toString(fileBuffer, 'base64'); // Convert file buffer to base64
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType, fileData);
2024-06-14 09:43:17 -04:00
}
}
2024-06-11 17:40:02 -04:00
export default FileMessage;