mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
fix: use correct status code for throwing media error
This commit is contained in:
@@ -4,7 +4,7 @@ import NodeCache from 'node-cache'
|
|||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
import { WA_DEFAULT_EPHEMERAL } from '../Defaults'
|
||||||
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types'
|
||||||
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
import { aggregateMessageKeysNotFromMe, assertMediaContent, bindWaitForEvent, decryptMediaRetryData, encodeWAMessage, encryptMediaRetryRequest, encryptSenderKeyMsgSignalProto, encryptSignalProto, extractDeviceJids, generateMessageID, generateWAMessage, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, jidToSignalProtocolAddress, parseAndInjectE2ESessions, unixTimestampSeconds } from '../Utils'
|
||||||
import { getUrlInfo } from '../Utils/link-preview'
|
import { getUrlInfo } from '../Utils/link-preview'
|
||||||
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
import { areJidsSameUser, BinaryNode, BinaryNodeAttributes, getBinaryNodeChild, getBinaryNodeChildren, isJidGroup, isJidUser, jidDecode, jidEncode, jidNormalizedUser, JidWithDevice, S_WHATSAPP_NET } from '../WABinary'
|
||||||
import { makeGroupsSocket } from './groups'
|
import { makeGroupsSocket } from './groups'
|
||||||
@@ -543,7 +543,7 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
const resultStr = proto.MediaRetryNotification.MediaRetryNotificationResultType[media.result]
|
const resultStr = proto.MediaRetryNotification.MediaRetryNotificationResultType[media.result]
|
||||||
throw new Boom(
|
throw new Boom(
|
||||||
`Media re-upload failed by device (${resultStr})`,
|
`Media re-upload failed by device (${resultStr})`,
|
||||||
{ data: media, statusCode: MEDIA_RETRY_STATUS_MAP[media.result] || 404 }
|
{ data: media, statusCode: getStatusCodeForMediaRetry(media.result) || 404 }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,11 +623,4 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MEDIA_RETRY_STATUS_MAP = {
|
|
||||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.SUCCESS]: 200,
|
|
||||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.DECRYPTION_ERROR]: 412,
|
|
||||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.NOT_FOUND]: 404,
|
|
||||||
[proto.MediaRetryNotification.MediaRetryNotificationResultType.GENERAL_ERROR]: 418,
|
|
||||||
} as const
|
|
||||||
@@ -633,7 +633,10 @@ export const decodeMediaRetryNode = (node: BinaryNode) => {
|
|||||||
const errorNode = getBinaryNodeChild(node, 'error')
|
const errorNode = getBinaryNodeChild(node, 'error')
|
||||||
if(errorNode) {
|
if(errorNode) {
|
||||||
const errorCode = +errorNode.attrs.code
|
const errorCode = +errorNode.attrs.code
|
||||||
event.error = new Boom(`Failed to re-upload media (${errorCode})`, { data: errorNode.attrs })
|
event.error = new Boom(
|
||||||
|
`Failed to re-upload media (${errorCode})`,
|
||||||
|
{ data: errorNode.attrs, statusCode: getStatusCodeForMediaRetry(errorCode) }
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt')
|
const encryptedInfoNode = getBinaryNodeChild(node, 'encrypt')
|
||||||
const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p')
|
const ciphertext = getBinaryNodeChildBuffer(encryptedInfoNode, 'enc_p')
|
||||||
@@ -656,4 +659,13 @@ export const decryptMediaRetryData = (
|
|||||||
const retryKey = getMediaRetryKey(mediaKey)
|
const retryKey = getMediaRetryKey(mediaKey)
|
||||||
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId))
|
const plaintext = aesDecryptGCM(ciphertext, retryKey, iv, Buffer.from(msgId))
|
||||||
return proto.MediaRetryNotification.decode(plaintext)
|
return proto.MediaRetryNotification.decode(plaintext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getStatusCodeForMediaRetry = (code: number) => MEDIA_RETRY_STATUS_MAP[code]
|
||||||
|
|
||||||
|
const MEDIA_RETRY_STATUS_MAP = {
|
||||||
|
[proto.MediaRetryNotification.MediaRetryNotificationResultType.SUCCESS]: 200,
|
||||||
|
[proto.MediaRetryNotification.MediaRetryNotificationResultType.DECRYPTION_ERROR]: 412,
|
||||||
|
[proto.MediaRetryNotification.MediaRetryNotificationResultType.NOT_FOUND]: 404,
|
||||||
|
[proto.MediaRetryNotification.MediaRetryNotificationResultType.GENERAL_ERROR]: 418,
|
||||||
|
} as const
|
||||||
|
|||||||
Reference in New Issue
Block a user