Merge branch 'master' of https://github.com/WhiskeySockets/Baileys into fix-eslint-prettier-editorconfig-rules
This commit is contained in:
+40
-31
@@ -165,8 +165,17 @@ export const prepareWAMessageMedia = async (message: AnyMediaMessageContent, opt
|
||||
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true
|
||||
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true
|
||||
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation
|
||||
const { mediaKey, encWriteStream, bodyPath, fileEncSha256, fileSha256, fileLength, didSaveToTmpPath } =
|
||||
await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
|
||||
const {
|
||||
mediaKey,
|
||||
encFilePath,
|
||||
originalFilePath,
|
||||
fileEncSha256,
|
||||
fileSha256,
|
||||
fileLength
|
||||
} = await encryptedStream(
|
||||
uploadData.media,
|
||||
options.mediaTypeOverride || mediaType,
|
||||
{
|
||||
logger,
|
||||
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
||||
opts: options.options
|
||||
@@ -174,23 +183,21 @@ export const prepareWAMessageMedia = async (message: AnyMediaMessageContent, opt
|
||||
// url safe Base64 encode the SHA256 hash of the body
|
||||
const fileEncSha256B64 = fileEncSha256.toString('base64')
|
||||
const [{ mediaUrl, directPath }] = await Promise.all([
|
||||
(async () => {
|
||||
const result = await options.upload(encWriteStream, {
|
||||
fileEncSha256B64,
|
||||
mediaType,
|
||||
timeoutMs: options.mediaUploadTimeoutMs
|
||||
})
|
||||
(async() => {
|
||||
const result = await options.upload(
|
||||
encFilePath,
|
||||
{ fileEncSha256B64, mediaType, timeoutMs: options.mediaUploadTimeoutMs }
|
||||
)
|
||||
logger?.debug({ mediaType, cacheableKey }, 'uploaded media')
|
||||
return result
|
||||
})(),
|
||||
(async () => {
|
||||
try {
|
||||
if (requiresThumbnailComputation) {
|
||||
const { thumbnail, originalImageDimensions } = await generateThumbnail(
|
||||
bodyPath!,
|
||||
mediaType as 'image' | 'video',
|
||||
options
|
||||
)
|
||||
if(requiresThumbnailComputation) {
|
||||
const {
|
||||
thumbnail,
|
||||
originalImageDimensions
|
||||
} = await generateThumbnail(originalFilePath!, mediaType as 'image' | 'video', options)
|
||||
uploadData.jpegThumbnail = thumbnail
|
||||
if (!uploadData.width && originalImageDimensions) {
|
||||
uploadData.width = originalImageDimensions.width
|
||||
@@ -201,13 +208,13 @@ export const prepareWAMessageMedia = async (message: AnyMediaMessageContent, opt
|
||||
logger?.debug('generated thumbnail')
|
||||
}
|
||||
|
||||
if (requiresDurationComputation) {
|
||||
uploadData.seconds = await getAudioDuration(bodyPath!)
|
||||
if(requiresDurationComputation) {
|
||||
uploadData.seconds = await getAudioDuration(originalFilePath!)
|
||||
logger?.debug('computed audio duration')
|
||||
}
|
||||
|
||||
if (requiresWaveformProcessing) {
|
||||
uploadData.waveform = await getAudioWaveform(bodyPath!, logger)
|
||||
if(requiresWaveformProcessing) {
|
||||
uploadData.waveform = await getAudioWaveform(originalFilePath!, logger)
|
||||
logger?.debug('processed waveform')
|
||||
}
|
||||
|
||||
@@ -218,20 +225,22 @@ export const prepareWAMessageMedia = async (message: AnyMediaMessageContent, opt
|
||||
} catch (error) {
|
||||
logger?.warn({ trace: error.stack }, 'failed to obtain extra info')
|
||||
}
|
||||
})()
|
||||
]).finally(async () => {
|
||||
encWriteStream.destroy()
|
||||
// remove tmp files
|
||||
if (didSaveToTmpPath && bodyPath) {
|
||||
try {
|
||||
await fs.access(bodyPath)
|
||||
await fs.unlink(bodyPath)
|
||||
logger?.debug('removed tmp file')
|
||||
} catch (error) {
|
||||
logger?.warn('failed to remove tmp file')
|
||||
})(),
|
||||
])
|
||||
.finally(
|
||||
async() => {
|
||||
try {
|
||||
await fs.unlink(encFilePath)
|
||||
if(originalFilePath) {
|
||||
await fs.unlink(originalFilePath)
|
||||
}
|
||||
|
||||
logger?.debug('removed tmp files')
|
||||
} catch(error) {
|
||||
logger?.warn('failed to remove tmp file')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
const obj = WAProto.Message.fromObject({
|
||||
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
||||
|
||||
Reference in New Issue
Block a user