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:
Pedro S. Lopez
2021-08-01 23:29:06 -04:00
committed by GitHub
parent 628b6e4d49
commit d9ccb6f276

View File

@@ -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,
mimetype: msg.mimetype,
filename: msg.filename
};
return {
data,
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;