Fix downloading media for WhatsApp Web v2.2126.10 (#735)

* fix downloadMedia

* return a boolean for hasMedia
This commit is contained in:
Pedro S. Lopez
2021-07-09 02:38:31 -04:00
committed by GitHub
parent 0465507009
commit 0ef6061d7e
2 changed files with 21 additions and 43 deletions

View File

@@ -35,6 +35,7 @@ exports.ExposeStore = (moduleRaidStr) => {
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].default;
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.DownloadManager = window.mR.findModule('DownloadManager')[0].default;
};
exports.LoadUtils = () => {
@@ -349,43 +350,14 @@ exports.LoadUtils = () => {
});
};
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);
});
window.WWebJS.arrayBufferToBase64 = async (arrayBuffer) => {
let binary = '';
const bytes = new Uint8Array( arrayBuffer );
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
};
window.WWebJS.getFileHash = async (data) => {