mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-20 12:39:20 +00:00
fix: correctly resolve media that hasn't been downloaded (#763)
* fix: correctly abort if media does not exist * catch 404s * dont throw for media that cant be fetched
This commit is contained in:
@@ -313,32 +313,39 @@ class Message extends Base {
|
|||||||
|
|
||||||
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
if (msg.mediaData.mediaStage != 'RESOLVED') {
|
||||||
// try to resolve media
|
// try to resolve media
|
||||||
await msg.downloadMedia(true, 1);
|
await msg.downloadMedia({
|
||||||
|
downloadEvenIfExpensive: true,
|
||||||
|
rmrReason: 1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.mediaData.mediaStage.includes('ERROR')) {
|
if (msg.mediaData.mediaStage.includes('ERROR') || msg.mediaData.mediaStage === 'FETCHING') {
|
||||||
// media could not be downloaded
|
// media could not be downloaded
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
|
try {
|
||||||
directPath: msg.directPath,
|
const decryptedMedia = await window.Store.DownloadManager.downloadAndDecrypt({
|
||||||
encFilehash: msg.encFilehash,
|
directPath: msg.directPath,
|
||||||
filehash: msg.filehash,
|
encFilehash: msg.encFilehash,
|
||||||
mediaKey: msg.mediaKey,
|
filehash: msg.filehash,
|
||||||
mediaKeyTimestamp: msg.mediaKeyTimestamp,
|
mediaKey: msg.mediaKey,
|
||||||
type: msg.type,
|
mediaKeyTimestamp: msg.mediaKeyTimestamp,
|
||||||
signal: (new AbortController).signal
|
type: msg.type,
|
||||||
});
|
signal: (new AbortController).signal
|
||||||
|
});
|
||||||
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
|
|
||||||
|
const data = window.WWebJS.arrayBufferToBase64(decryptedMedia);
|
||||||
return {
|
|
||||||
data,
|
return {
|
||||||
mimetype: msg.mimetype,
|
data,
|
||||||
filename: msg.filename
|
mimetype: msg.mimetype,
|
||||||
};
|
filename: msg.filename
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
if(e.status && e.status === 404) return undefined;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}, this.id._serialized);
|
}, this.id._serialized);
|
||||||
|
|
||||||
if (!result) return undefined;
|
if (!result) return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user