mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 04:29:15 +00:00
Fix downloading media for WhatsApp Web v2.2126.10 (#735)
* fix downloadMedia * return a boolean for hasMedia
This commit is contained in:
@@ -41,7 +41,7 @@ class Message extends Base {
|
|||||||
* Indicates if the message has media available for download
|
* Indicates if the message has media available for download
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.hasMedia = data.clientUrl || data.deprecatedMms3Url;
|
this.hasMedia = Boolean(data.mediaKey && data.directPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message content
|
* Message content
|
||||||
@@ -312,14 +312,20 @@ class Message extends Base {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaUrl = msg.clientUrl || msg.deprecatedMms3Url;
|
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
|
||||||
|
directPath: msg.directPath,
|
||||||
|
encFilehash: msg.encFilehash,
|
||||||
|
filehash: msg.filehash,
|
||||||
|
mediaKey: msg.mediaKey,
|
||||||
|
mediaKeyTimestamp: msg.mediaKeyTimestamp,
|
||||||
|
type: msg.type,
|
||||||
|
signal: (new AbortController).signal
|
||||||
|
});
|
||||||
|
|
||||||
const buffer = await window.WWebJS.downloadBuffer(mediaUrl);
|
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
|
||||||
const decrypted = await window.Store.CryptoLib.decryptE2EMedia(msg.type, buffer, msg.mediaKey, msg.mimetype);
|
|
||||||
const data = await window.WWebJS.readBlobAsync(decrypted._blob);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: data.split(',')[1],
|
data,
|
||||||
mimetype: msg.mimetype,
|
mimetype: msg.mimetype,
|
||||||
filename: msg.filename
|
filename: msg.filename
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
|||||||
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].default;
|
window.Store.Features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0].default;
|
||||||
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
|
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
|
||||||
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
|
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
|
||||||
|
window.Store.DownloadManager = window.mR.findModule('DownloadManager')[0].default;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.LoadUtils = () => {
|
exports.LoadUtils = () => {
|
||||||
@@ -349,43 +350,14 @@ exports.LoadUtils = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
window.WWebJS.downloadBuffer = (url) => {
|
window.WWebJS.arrayBufferToBase64 = async (arrayBuffer) => {
|
||||||
return new Promise(function (resolve, reject) {
|
let binary = '';
|
||||||
let xhr = new XMLHttpRequest();
|
const bytes = new Uint8Array( arrayBuffer );
|
||||||
xhr.open('GET', url);
|
const len = bytes.byteLength;
|
||||||
xhr.responseType = 'arraybuffer';
|
for (let i = 0; i < len; i++) {
|
||||||
xhr.onload = function () {
|
binary += String.fromCharCode( bytes[ i ] );
|
||||||
if (xhr.status == 200) {
|
}
|
||||||
resolve(xhr.response);
|
return window.btoa( binary );
|
||||||
} 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.getFileHash = async (data) => {
|
window.WWebJS.getFileHash = async (data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user