fix: ensure media cache does not override caption & other properties

This commit is contained in:
Adhiraj Singh
2021-12-29 14:10:00 +05:30
parent 3534221e11
commit 03f33852df

View File

@@ -77,14 +77,6 @@ export const prepareWAMessageMedia = async(
// generate the key
mediaType + ':' + uploadData.media.url!.toString()
)
// check for cache hit
if(cacheableKey) {
const mediaBuff: Buffer = options.mediaCache!.get(cacheableKey)
if(mediaBuff) {
logger?.debug({ cacheableKey }, `got media cache hit`)
return WAProto.Message.decode(mediaBuff)
}
}
if(mediaType === 'document' && !uploadData.fileName) {
uploadData.fileName = 'file'
@@ -92,6 +84,18 @@ export const prepareWAMessageMedia = async(
if(!uploadData.mimetype) {
uploadData.mimetype = MIMETYPE_MAP[mediaType]
}
// check for cache hit
if(cacheableKey) {
const mediaBuff: Buffer = options.mediaCache!.get(cacheableKey)
if(mediaBuff) {
logger?.debug({ cacheableKey }, `got media cache hit`)
const obj = WAProto.Message.decode(mediaBuff)
const key = `${mediaType}Message`
return Object.assign(obj[key], { ...uploadData })
}
}
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined'
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') &&
(typeof uploadData['jpegThumbnail'] === 'undefined')