mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 11:39:14 +00:00
Download message attachments (images, documents, etc)
This commit is contained in:
@@ -8,12 +8,12 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.mR = moduleRaid();
|
||||
window.Store = window.mR.findModule("Chat")[1].default;
|
||||
window.Store.AppState = window.mR.findModule("STREAM")[0].default;
|
||||
|
||||
window.Store.CryptoLib = window.mR.findModule("decryptE2EMedia")[0];
|
||||
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
||||
window.Store.SendMessage = window.mR.findModule("sendTextMsgToChat")[0].sendTextMsgToChat;
|
||||
}
|
||||
|
||||
exports.LoadCustomSerializers = () => {
|
||||
exports.LoadUtils = () => {
|
||||
window.WWebJS = {};
|
||||
|
||||
window.WWebJS.getChatModel = chat => {
|
||||
@@ -37,6 +37,45 @@ exports.LoadCustomSerializers = () => {
|
||||
const chats = Store.Chat.models;
|
||||
return chats.map(chat => WWebJS.getChatModel(chat));
|
||||
}
|
||||
|
||||
window.WWebJS.downloadBuffer = (url) => {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", url);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onload = function () {
|
||||
if (xhr.status == 200) {
|
||||
resolve(xhr.response);
|
||||
} else {
|
||||
reject({
|
||||
status: this.status,
|
||||
statusText: xhr.statusText
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
reject({
|
||||
status: this.status,
|
||||
statusText: xhr.statusText
|
||||
});
|
||||
};
|
||||
xhr.send(null);
|
||||
});
|
||||
}
|
||||
|
||||
window.WWebJS.readBlobAsync = (blob) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
resolve(reader.result);
|
||||
};
|
||||
|
||||
reader.onerror = reject;
|
||||
|
||||
reader.readAsDataURL(blob);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exports.MarkAllRead = () => {
|
||||
|
||||
Reference in New Issue
Block a user