mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: map all WA media types
This commit is contained in:
@@ -60,17 +60,37 @@ export const DEFAULT_LEGACY_CONNECTION_CONFIG: LegacySocketConfig = {
|
|||||||
expectResponseTimeout: 60_000,
|
expectResponseTimeout: 60_000,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MEDIA_PATH_MAP: { [T in MediaType]: string } = {
|
export const MEDIA_PATH_MAP: { [T in MediaType]?: string } = {
|
||||||
image: '/mms/image',
|
image: '/mms/image',
|
||||||
video: '/mms/video',
|
video: '/mms/video',
|
||||||
document: '/mms/document',
|
document: '/mms/document',
|
||||||
audio: '/mms/audio',
|
audio: '/mms/audio',
|
||||||
sticker: '/mms/image',
|
sticker: '/mms/image',
|
||||||
history: '',
|
'thumbnail-link': '/mms/image',
|
||||||
'product-image': '/product/image',
|
'product-catalog-image': '/product/image',
|
||||||
'md-app-state': ''
|
'md-app-state': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const MEDIA_HKDF_KEY_MAPPING = {
|
||||||
|
'audio': 'Audio',
|
||||||
|
'document': 'Document',
|
||||||
|
'gif': 'Video',
|
||||||
|
'image': 'Image',
|
||||||
|
'ppic': '',
|
||||||
|
'product': 'Image',
|
||||||
|
'ptt': 'Audio',
|
||||||
|
'sticker': 'Image',
|
||||||
|
'video': 'Video',
|
||||||
|
'thumbnail-document': 'Document Thumbnail',
|
||||||
|
'thumbnail-image': 'Image Thumbnail',
|
||||||
|
'thumbnail-video': 'Video Thumbnail',
|
||||||
|
'thumbnail-link': 'Link Thumbnail',
|
||||||
|
'md-msg-hist': 'History',
|
||||||
|
'md-app-state': 'App State',
|
||||||
|
'product-catalog-image': '',
|
||||||
|
'payment-bg-image': 'Payment Background',
|
||||||
|
}
|
||||||
|
|
||||||
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
|
export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP) as MediaType[]
|
||||||
|
|
||||||
export const MIN_PREKEY_COUNT = 5
|
export const MIN_PREKEY_COUNT = 5
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { Logger } from 'pino'
|
|||||||
import type { Readable } from 'stream'
|
import type { Readable } from 'stream'
|
||||||
import type { URL } from 'url'
|
import type { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
|
import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults'
|
||||||
import type { GroupMetadata } from './GroupMetadata'
|
import type { GroupMetadata } from './GroupMetadata'
|
||||||
|
|
||||||
// export the WAMessage Prototypes
|
// export the WAMessage Prototypes
|
||||||
@@ -75,7 +76,8 @@ type WithDimensions = {
|
|||||||
width?: number
|
width?: number
|
||||||
height?: number
|
height?: number
|
||||||
}
|
}
|
||||||
export type MediaType = 'image' | 'video' | 'sticker' | 'audio' | 'document' | 'history' | 'md-app-state' | 'product-image'
|
|
||||||
|
export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING
|
||||||
export type AnyMediaMessageContent = (
|
export type AnyMediaMessageContent = (
|
||||||
({
|
({
|
||||||
image: WAMediaUpload
|
image: WAMediaUpload
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ export const uploadingNecessaryImages = async(
|
|||||||
const { directPath } = await waUploadToServer(
|
const { directPath } = await waUploadToServer(
|
||||||
toReadable(Buffer.concat(contentBlocks)),
|
toReadable(Buffer.concat(contentBlocks)),
|
||||||
{
|
{
|
||||||
mediaType: 'product-image',
|
mediaType: 'product-catalog-image',
|
||||||
fileEncSha256B64: sha,
|
fileEncSha256B64: sha,
|
||||||
timeoutMs
|
timeoutMs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { downloadContentFromMessage } from './messages-media'
|
|||||||
const inflatePromise = promisify(inflate)
|
const inflatePromise = promisify(inflate)
|
||||||
|
|
||||||
export const downloadHistory = async(msg: proto.Message.IHistorySyncNotification) => {
|
export const downloadHistory = async(msg: proto.Message.IHistorySyncNotification) => {
|
||||||
const stream = await downloadContentFromMessage(msg, 'history')
|
const stream = await downloadContentFromMessage(msg, 'md-msg-hist')
|
||||||
const bufferArray: Buffer[] = []
|
const bufferArray: Buffer[] = []
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
bufferArray.push(chunk)
|
bufferArray.push(chunk)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { Logger } from 'pino'
|
|||||||
import { Readable, Transform } from 'stream'
|
import { Readable, Transform } from 'stream'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
import { proto } from '../../WAProto'
|
import { proto } from '../../WAProto'
|
||||||
import { DEFAULT_ORIGIN, MEDIA_PATH_MAP } from '../Defaults'
|
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults'
|
||||||
import { BaileysEventMap, CommonSocketConfig, DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, MessageType, WAGenericMediaMessage, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types'
|
import { BaileysEventMap, CommonSocketConfig, DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, MessageType, WAGenericMediaMessage, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types'
|
||||||
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary'
|
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary'
|
||||||
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto'
|
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto'
|
||||||
@@ -50,16 +50,7 @@ const getImageProcessingLibrary = async() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const hkdfInfoKey = (type: MediaType) => {
|
export const hkdfInfoKey = (type: MediaType) => {
|
||||||
let str: string = type
|
const hkdfInfo = MEDIA_HKDF_KEY_MAPPING[type]
|
||||||
if(type === 'sticker') {
|
|
||||||
str = 'image'
|
|
||||||
}
|
|
||||||
|
|
||||||
if(type === 'md-app-state') {
|
|
||||||
str = 'App State'
|
|
||||||
}
|
|
||||||
|
|
||||||
const hkdfInfo = str[0].toUpperCase() + str.slice(1)
|
|
||||||
return `WhatsApp ${hkdfInfo} Keys`
|
return `WhatsApp ${hkdfInfo} Keys`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,15 +37,13 @@ type MediaUploadData = {
|
|||||||
mimetype?: string
|
mimetype?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const MIMETYPE_MAP: { [T in MediaType]: string } = {
|
const MIMETYPE_MAP: { [T in MediaType]?: string } = {
|
||||||
image: 'image/jpeg',
|
image: 'image/jpeg',
|
||||||
video: 'video/mp4',
|
video: 'video/mp4',
|
||||||
document: 'application/pdf',
|
document: 'application/pdf',
|
||||||
audio: 'audio/ogg; codecs=opus',
|
audio: 'audio/ogg; codecs=opus',
|
||||||
sticker: 'image/webp',
|
sticker: 'image/webp',
|
||||||
history: 'application/x-protobuf',
|
'product-catalog-image': 'image/jpeg',
|
||||||
'product-image': 'image/jpeg',
|
|
||||||
'md-app-state': 'application/x-protobuf',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MessageTypeProto = {
|
const MessageTypeProto = {
|
||||||
|
|||||||
Reference in New Issue
Block a user