Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| acfaaff68b | |||
| 4fa7d4ee11 | |||
| cf72068b6c |
@@ -69,7 +69,7 @@ import {
|
|||||||
recordMessageReceived,
|
recordMessageReceived,
|
||||||
recordMessageRetry
|
recordMessageRetry
|
||||||
} from '../Utils/prometheus-metrics.js'
|
} from '../Utils/prometheus-metrics.js'
|
||||||
import { isTcTokenExpired, resolveTcTokenJid } from '../Utils/tc-token-utils'
|
import { isTcTokenExpired, resolveTcTokenJid, storeTcTokensFromIqResult } from '../Utils/tc-token-utils'
|
||||||
import {
|
import {
|
||||||
areJidsSameUser,
|
areJidsSameUser,
|
||||||
type BinaryNode,
|
type BinaryNode,
|
||||||
@@ -1453,6 +1453,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// When a session is refreshed (identity change), re-issue tctoken fire-and-forget
|
// When a session is refreshed (identity change), re-issue tctoken fire-and-forget
|
||||||
|
// WABA Android: reissue stores senderTimestamp + realIssueTimestamp after IQ success
|
||||||
if (result.action === 'session_refreshed') {
|
if (result.action === 'session_refreshed') {
|
||||||
const normalizedJid = jidNormalizedUser(from)
|
const normalizedJid = jidNormalizedUser(from)
|
||||||
resolveTcTokenJid(normalizedJid, getLIDForPN)
|
resolveTcTokenJid(normalizedJid, getLIDForPN)
|
||||||
@@ -1462,9 +1463,36 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
if (entry?.token?.length && !isTcTokenExpired(entry.timestamp)) {
|
if (entry?.token?.length && !isTcTokenExpired(entry.timestamp)) {
|
||||||
const senderTs = unixTimestampSeconds()
|
const senderTs = unixTimestampSeconds()
|
||||||
logTcToken('reissue', { jid: normalizedJid, reason: 'session_refreshed' })
|
logTcToken('reissue', { jid: normalizedJid, reason: 'session_refreshed' })
|
||||||
getPrivacyTokens([normalizedJid], senderTs).catch(err => {
|
getPrivacyTokens([normalizedJid], senderTs)
|
||||||
logTcToken('reissue_fail', { jid: normalizedJid, error: err?.message })
|
.then(async (iqResult) => {
|
||||||
})
|
await storeTcTokensFromIqResult({
|
||||||
|
result: iqResult,
|
||||||
|
fallbackJid: normalizedJid,
|
||||||
|
keys: authState.keys,
|
||||||
|
getLIDForPN,
|
||||||
|
onNewJidStored: (storedJid) => {
|
||||||
|
tcTokenKnownJids.add(storedJid)
|
||||||
|
scheduleTcTokenIndexSave()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// Persist senderTimestamp + realIssueTimestamp after IQ success
|
||||||
|
const currentData = await authState.keys.get('tctoken', [tcJid])
|
||||||
|
const currentEntry = currentData[tcJid]
|
||||||
|
await authState.keys.set({
|
||||||
|
tctoken: {
|
||||||
|
[tcJid]: {
|
||||||
|
...currentEntry,
|
||||||
|
token: currentEntry?.token ?? Buffer.alloc(0),
|
||||||
|
senderTimestamp: senderTs,
|
||||||
|
realIssueTimestamp: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logTcToken('reissue_ok', { jid: normalizedJid, reason: 'session_refreshed' })
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
logTcToken('reissue_fail', { jid: normalizedJid, error: err?.message })
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@@ -1912,7 +1940,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
[storageJid]: {
|
[storageJid]: {
|
||||||
...existing,
|
...existing,
|
||||||
token: Buffer.from(content),
|
token: Buffer.from(content),
|
||||||
timestamp
|
timestamp,
|
||||||
|
// WABA Android: resets real_issue_timestamp when a new incoming token arrives
|
||||||
|
// (UPDATE wa_trusted_contacts_send SET real_issue_timestamp=null)
|
||||||
|
realIssueTimestamp: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -2823,6 +2854,24 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
const jid = jidNormalizedUser(attrs.from)
|
const jid = jidNormalizedUser(attrs.from)
|
||||||
logTcToken('error_463', { jid, msgId })
|
logTcToken('error_463', { jid, msgId })
|
||||||
|
|
||||||
|
// WABA Android: error 463 triggers getPrivacyTokens() fire-and-forget
|
||||||
|
// to ensure token is available for the retry below
|
||||||
|
getPrivacyTokens([jid])
|
||||||
|
.then(async (result) => {
|
||||||
|
await storeTcTokensFromIqResult({
|
||||||
|
result,
|
||||||
|
fallbackJid: jid,
|
||||||
|
keys: authState.keys,
|
||||||
|
getLIDForPN,
|
||||||
|
onNewJidStored: (storedJid) => {
|
||||||
|
tcTokenKnownJids.add(storedJid)
|
||||||
|
scheduleTcTokenIndexSave()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logTcToken('fetched', { jid, reason: 'error_463' })
|
||||||
|
})
|
||||||
|
.catch(() => { /* fire-and-forget */ })
|
||||||
|
|
||||||
// Single-retry: wait 1.5s for the server's tctoken notification to arrive,
|
// Single-retry: wait 1.5s for the server's tctoken notification to arrive,
|
||||||
// then resend. A Set prevents infinite retry loops.
|
// then resend. A Set prevents infinite retry loops.
|
||||||
// Composite key (jid:msgId) ensures retries are isolated per destination.
|
// Composite key (jid:msgId) ensures retries are isolated per destination.
|
||||||
@@ -2858,7 +2907,24 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (attrs.error === SERVER_ERROR_CODES.SmaxInvalid) {
|
} else if (attrs.error === SERVER_ERROR_CODES.SmaxInvalid) {
|
||||||
logTcToken('error_479', { jid: attrs.from, msgId: attrs.id })
|
const jid479 = jidNormalizedUser(attrs.from)
|
||||||
|
logTcToken('error_479', { jid: jid479, msgId: attrs.id })
|
||||||
|
// WABA Android: error 479 (SmaxInvalid) also triggers token re-fetch
|
||||||
|
getPrivacyTokens([jid479])
|
||||||
|
.then(async (result) => {
|
||||||
|
await storeTcTokensFromIqResult({
|
||||||
|
result,
|
||||||
|
fallbackJid: jid479,
|
||||||
|
keys: authState.keys,
|
||||||
|
getLIDForPN,
|
||||||
|
onNewJidStored: (storedJid) => {
|
||||||
|
tcTokenKnownJids.add(storedJid)
|
||||||
|
scheduleTcTokenIndexSave()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logTcToken('fetched', { jid: jid479, reason: 'error_479' })
|
||||||
|
})
|
||||||
|
.catch(() => { /* fire-and-forget */ })
|
||||||
} else {
|
} else {
|
||||||
logger.warn({ attrs }, 'received error in ack')
|
logger.warn({ attrs }, 'received error in ack')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1611,6 +1611,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
|
|
||||||
// Persist senderTimestamp unconditionally — WA Web stores it in the chat table
|
// Persist senderTimestamp unconditionally — WA Web stores it in the chat table
|
||||||
// regardless of whether a token exists. Spread preserves token+timestamp if present.
|
// regardless of whether a token exists. Spread preserves token+timestamp if present.
|
||||||
|
// WABA Android: INSERT INTO wa_trusted_contacts_send (jid, sent_tc_token_timestamp, real_issue_timestamp)
|
||||||
|
// VALUES (?, ?, 0) — realIssueTimestamp=0 means issued but not yet confirmed by server
|
||||||
const currentData = await authState.keys.get('tctoken', [tcTokenJid])
|
const currentData = await authState.keys.get('tctoken', [tcTokenJid])
|
||||||
const currentEntry = currentData[tcTokenJid]
|
const currentEntry = currentData[tcTokenJid]
|
||||||
await authState.keys.set({
|
await authState.keys.set({
|
||||||
@@ -1618,7 +1620,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
|
|||||||
[tcTokenJid]: {
|
[tcTokenJid]: {
|
||||||
...currentEntry,
|
...currentEntry,
|
||||||
token: currentEntry?.token ?? Buffer.alloc(0),
|
token: currentEntry?.token ?? Buffer.alloc(0),
|
||||||
senderTimestamp: issueTimestamp
|
senderTimestamp: issueTimestamp,
|
||||||
|
realIssueTimestamp: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ export type SignalDataTypeMap = {
|
|||||||
'app-state-sync-version': LTHashState
|
'app-state-sync-version': LTHashState
|
||||||
'lid-mapping': string
|
'lid-mapping': string
|
||||||
'device-list': string[]
|
'device-list': string[]
|
||||||
tctoken: { token: Buffer; timestamp?: string; senderTimestamp?: number }
|
tctoken: { token: Buffer; timestamp?: string; senderTimestamp?: number; realIssueTimestamp?: number | null }
|
||||||
/** Identity key for Signal Protocol - used for detecting contact reinstalls */
|
/** Identity key for Signal Protocol - used for detecting contact reinstalls */
|
||||||
'identity-key': Uint8Array
|
'identity-key': Uint8Array
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,12 +54,14 @@ export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL
|
|||||||
* Individual sticker in a sticker pack
|
* Individual sticker in a sticker pack
|
||||||
*/
|
*/
|
||||||
export type Sticker = {
|
export type Sticker = {
|
||||||
/** Buffer, Stream or URL of the sticker image (will be converted to WebP if needed) */
|
/** Buffer, Stream or URL of the sticker image (WebP or Lottie/WAS format) */
|
||||||
data: WAMediaUpload
|
data: WAMediaUpload
|
||||||
/** Array of emojis associated with this sticker (max 3 recommended per WhatsApp standards) */
|
/** Array of emojis associated with this sticker (max 3 recommended per WhatsApp standards) */
|
||||||
emojis?: string[]
|
emojis?: string[]
|
||||||
/** Accessibility label for screen readers (max 125 chars for static, 255 for animated) */
|
/** Accessibility label for screen readers (max 125 chars for static, 255 for animated) */
|
||||||
accessibilityLabel?: string
|
accessibilityLabel?: string
|
||||||
|
/** Force Lottie format detection (auto-detected if omitted) */
|
||||||
|
isLottie?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+120
-19
@@ -2,6 +2,7 @@ import { Boom } from '@hapi/boom'
|
|||||||
import { createHash } from 'crypto'
|
import { createHash } from 'crypto'
|
||||||
import { zipSync } from 'fflate'
|
import { zipSync } from 'fflate'
|
||||||
import { promises as fs } from 'fs'
|
import { promises as fs } from 'fs'
|
||||||
|
import { gzipSync, gunzipSync } from 'zlib'
|
||||||
import { proto } from '../../WAProto/index.js'
|
import { proto } from '../../WAProto/index.js'
|
||||||
import type { MediaType } from '../Defaults/index.js'
|
import type { MediaType } from '../Defaults/index.js'
|
||||||
import type { StickerPack, WAMediaUpload, WAMediaUploadFunction } from '../Types/Message.js'
|
import type { StickerPack, WAMediaUpload, WAMediaUploadFunction } from '../Types/Message.js'
|
||||||
@@ -101,6 +102,49 @@ export const isAnimatedWebP = (buffer: Buffer): boolean => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detecta se um buffer é Lottie JSON (raw ou gzip-compressed/WAS)
|
||||||
|
*
|
||||||
|
* WABA usa mimetype `application/was` para stickers Lottie.
|
||||||
|
* WAS (WhatsApp Animated Sticker) = gzip-compressed Lottie JSON.
|
||||||
|
*
|
||||||
|
* Detecção:
|
||||||
|
* - Gzip (0x1f 0x8b): descomprime e verifica se é Lottie JSON
|
||||||
|
* - JSON bruto: verifica campos Lottie obrigatórios (v, ip, op, layers)
|
||||||
|
*
|
||||||
|
* @param buffer - Buffer to check
|
||||||
|
* @returns true if buffer is Lottie/WAS format
|
||||||
|
*/
|
||||||
|
export const isLottieBuffer = (buffer: Buffer): boolean => {
|
||||||
|
if (buffer.length < 2) return false
|
||||||
|
|
||||||
|
let jsonBuffer: Buffer
|
||||||
|
|
||||||
|
// Check if gzip-compressed (WAS format)
|
||||||
|
if (buffer[0] === 0x1f && buffer[1] === 0x8b) {
|
||||||
|
try {
|
||||||
|
// SECURITY: Limit decompressed output to 50MB to prevent decompression bombs
|
||||||
|
jsonBuffer = gunzipSync(buffer, { maxOutputLength: 50 * 1024 * 1024 }) as Buffer
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if (buffer[0] === 0x7b) {
|
||||||
|
// Starts with '{' - could be raw Lottie JSON
|
||||||
|
jsonBuffer = buffer
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Lottie JSON structure: must have v, ip, op, AND layers
|
||||||
|
try {
|
||||||
|
const str = jsonBuffer.toString('utf8', 0, Math.min(jsonBuffer.length, 4096))
|
||||||
|
// Quick check for ALL required Lottie fields
|
||||||
|
return str.includes('"v"') && str.includes('"layers"') && str.includes('"ip"') && str.includes('"op"')
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converte uma imagem para WebP usando Sharp
|
* Converte uma imagem para WebP usando Sharp
|
||||||
* Preserva o buffer original se já for WebP para manter EXIF e animações
|
* Preserva o buffer original se já for WebP para manter EXIF e animações
|
||||||
@@ -114,12 +158,25 @@ export const isAnimatedWebP = (buffer: Buffer): boolean => {
|
|||||||
const convertToWebP = async (
|
const convertToWebP = async (
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
logger?: ILogger
|
logger?: ILogger
|
||||||
): Promise<{ webpBuffer: Buffer; isAnimated: boolean }> => {
|
): Promise<{ webpBuffer: Buffer; isAnimated: boolean; isLottie: boolean }> => {
|
||||||
|
// Lottie/WAS: ensure gzip-compressed format (WAS = gzip Lottie JSON)
|
||||||
|
if (isLottieBuffer(buffer)) {
|
||||||
|
let wasBuffer = buffer
|
||||||
|
// Raw Lottie JSON (starts with '{') must be gzipped to produce valid WAS
|
||||||
|
if (buffer[0] === 0x7b) {
|
||||||
|
logger?.trace('Raw Lottie JSON detected, gzip-compressing to WAS format')
|
||||||
|
wasBuffer = gzipSync(buffer) as Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
logger?.trace('Input is Lottie/WAS format')
|
||||||
|
return { webpBuffer: wasBuffer, isAnimated: true, isLottie: true }
|
||||||
|
}
|
||||||
|
|
||||||
// Se já é WebP, preserva o buffer original (mantém EXIF e animações)
|
// Se já é WebP, preserva o buffer original (mantém EXIF e animações)
|
||||||
if (isWebPBuffer(buffer)) {
|
if (isWebPBuffer(buffer)) {
|
||||||
const isAnimated = isAnimatedWebP(buffer)
|
const isAnimated = isAnimatedWebP(buffer)
|
||||||
logger?.trace({ isAnimated }, 'Input is already WebP, preserving original buffer')
|
logger?.trace({ isAnimated }, 'Input is already WebP, preserving original buffer')
|
||||||
return { webpBuffer: buffer, isAnimated }
|
return { webpBuffer: buffer, isAnimated, isLottie: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tenta usar Sharp para converter
|
// Tenta usar Sharp para converter
|
||||||
@@ -135,7 +192,7 @@ const convertToWebP = async (
|
|||||||
logger?.trace('Converting image to WebP using Sharp')
|
logger?.trace('Converting image to WebP using Sharp')
|
||||||
const webpBuffer = await lib.sharp.default(buffer).webp().toBuffer()
|
const webpBuffer = await lib.sharp.default(buffer).webp().toBuffer()
|
||||||
|
|
||||||
return { webpBuffer, isAnimated: false }
|
return { webpBuffer, isAnimated: false, isLottie: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -338,9 +395,11 @@ export type PrepareStickerPackMessageOptions = {
|
|||||||
*
|
*
|
||||||
* **Especificações WhatsApp:**
|
* **Especificações WhatsApp:**
|
||||||
* - 3-30 stickers por pack (oficial)
|
* - 3-30 stickers por pack (oficial)
|
||||||
* - WebP obrigatório
|
* - WebP ou Lottie/WAS (application/was)
|
||||||
|
* - Stickers: 512x512 pixels (auto-resize)
|
||||||
* - Recomendado: 100KB por sticker estático, 500KB animado
|
* - Recomendado: 100KB por sticker estático, 500KB animado
|
||||||
* - Tray icon: 252x252 pixels
|
* - Tray icon: 96x96 pixels (PNG no ZIP)
|
||||||
|
* - Thumbnail: 252x252 pixels (JPEG, upload separado)
|
||||||
*
|
*
|
||||||
* @param stickerPack - Sticker pack data with stickers, cover, name, publisher
|
* @param stickerPack - Sticker pack data with stickers, cover, name, publisher
|
||||||
* @param options - Upload function and optional logger
|
* @param options - Upload function and optional logger
|
||||||
@@ -464,9 +523,36 @@ export const prepareStickerPackMessage = async (
|
|||||||
// Obtém buffer do sticker
|
// Obtém buffer do sticker
|
||||||
const buffer = await mediaToBuffer(sticker.data, `sticker ${i + 1}`)
|
const buffer = await mediaToBuffer(sticker.data, `sticker ${i + 1}`)
|
||||||
|
|
||||||
// Converte para WebP
|
// Detecta formato e converte se necessário
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let { webpBuffer, isAnimated } = await convertToWebP(buffer, logger)
|
let { webpBuffer, isAnimated, isLottie } = await convertToWebP(buffer, logger)
|
||||||
|
|
||||||
|
// Validate explicit isLottie flag — must match detected format
|
||||||
|
if (sticker.isLottie !== undefined && sticker.isLottie !== isLottie) {
|
||||||
|
throw new Boom(
|
||||||
|
`Sticker ${i + 1}: explicit isLottie=${sticker.isLottie} does not match detected format (detected=${isLottie})`,
|
||||||
|
{ statusCode: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WABA: Enforce 512x512 dimensions for WebP stickers (Lottie is vector, skip)
|
||||||
|
if (!isLottie && isWebPBuffer(webpBuffer)) {
|
||||||
|
const lib = await getImageProcessingLibrary()
|
||||||
|
if (lib?.sharp) {
|
||||||
|
const metadata = await lib.sharp.default(webpBuffer).metadata()
|
||||||
|
if (metadata.width !== 512 || metadata.height !== 512) {
|
||||||
|
logger?.trace(
|
||||||
|
{ index: i, width: metadata.width, height: metadata.height },
|
||||||
|
'Resizing sticker to 512x512 (WABA standard)'
|
||||||
|
)
|
||||||
|
webpBuffer = await lib.sharp
|
||||||
|
.default(webpBuffer)
|
||||||
|
.resize(512, 512, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
||||||
|
.webp()
|
||||||
|
.toBuffer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ENHANCEMENT: Auto-compression if exceeds 1MB (try quality 70, then 50)
|
// ENHANCEMENT: Auto-compression if exceeds 1MB (try quality 70, then 50)
|
||||||
const MAX_STICKER_SIZE = 1024 * 1024 // 1MB
|
const MAX_STICKER_SIZE = 1024 * 1024 // 1MB
|
||||||
@@ -483,7 +569,7 @@ export const prepareStickerPackMessage = async (
|
|||||||
if (lib?.sharp) {
|
if (lib?.sharp) {
|
||||||
// Try quality 70
|
// Try quality 70
|
||||||
try {
|
try {
|
||||||
const compressed70 = await lib.sharp.default(buffer).webp({ quality: 70 }).toBuffer()
|
const compressed70 = await lib.sharp.default(webpBuffer).webp({ quality: 70 }).toBuffer()
|
||||||
|
|
||||||
// eslint-disable-next-line max-depth
|
// eslint-disable-next-line max-depth
|
||||||
if (compressed70.length <= MAX_STICKER_SIZE) {
|
if (compressed70.length <= MAX_STICKER_SIZE) {
|
||||||
@@ -498,7 +584,7 @@ export const prepareStickerPackMessage = async (
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Try quality 50
|
// Try quality 50
|
||||||
const compressed50 = await lib.sharp.default(buffer).webp({ quality: 50 }).toBuffer()
|
const compressed50 = await lib.sharp.default(webpBuffer).webp({ quality: 50 }).toBuffer()
|
||||||
|
|
||||||
// eslint-disable-next-line max-depth
|
// eslint-disable-next-line max-depth
|
||||||
if (compressed50.length <= MAX_STICKER_SIZE) {
|
if (compressed50.length <= MAX_STICKER_SIZE) {
|
||||||
@@ -547,12 +633,13 @@ export const prepareStickerPackMessage = async (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gera nome do arquivo: hash.webp (deduplicação automática)
|
// Gera nome do arquivo: hash.webp ou hash.was (WABA: plain_file_hash.ext)
|
||||||
const sha256Hash = generateSha256Hash(webpBuffer)
|
const sha256Hash = generateSha256Hash(webpBuffer)
|
||||||
const fileName = `${sha256Hash}.webp`
|
const extension = isLottie ? 'was' : 'webp'
|
||||||
|
const fileName = `${sha256Hash}.${extension}`
|
||||||
|
|
||||||
logger?.trace(
|
logger?.trace(
|
||||||
{ index: i, fileName, sizeKB: finalSizeKB.toFixed(2), isAnimated },
|
{ index: i, fileName, sizeKB: finalSizeKB.toFixed(2), isAnimated, isLottie },
|
||||||
'Sticker processed successfully'
|
'Sticker processed successfully'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -560,6 +647,7 @@ export const prepareStickerPackMessage = async (
|
|||||||
fileName,
|
fileName,
|
||||||
webpBuffer,
|
webpBuffer,
|
||||||
isAnimated,
|
isAnimated,
|
||||||
|
isLottie,
|
||||||
emojis: sticker.emojis || [],
|
emojis: sticker.emojis || [],
|
||||||
accessibilityLabel: sticker.accessibilityLabel
|
accessibilityLabel: sticker.accessibilityLabel
|
||||||
}
|
}
|
||||||
@@ -578,7 +666,7 @@ export const prepareStickerPackMessage = async (
|
|||||||
for (const result of processedStickers) {
|
for (const result of processedStickers) {
|
||||||
if (!result) continue
|
if (!result) continue
|
||||||
|
|
||||||
const { fileName, webpBuffer, isAnimated, emojis, accessibilityLabel } = result
|
const { fileName, webpBuffer, isAnimated, isLottie, emojis, accessibilityLabel } = result
|
||||||
|
|
||||||
// SECURITY FIX #7: Check if this hash already exists (duplicate sticker)
|
// SECURITY FIX #7: Check if this hash already exists (duplicate sticker)
|
||||||
const existingMetadata = metadataByHash.get(fileName)
|
const existingMetadata = metadataByHash.get(fileName)
|
||||||
@@ -605,13 +693,14 @@ export const prepareStickerPackMessage = async (
|
|||||||
// New sticker - add to ZIP and create metadata
|
// New sticker - add to ZIP and create metadata
|
||||||
stickerData[fileName] = [new Uint8Array(webpBuffer), { level: 0 as 0 }]
|
stickerData[fileName] = [new Uint8Array(webpBuffer), { level: 0 as 0 }]
|
||||||
|
|
||||||
|
// WABA: mimetype é 'application/was' para Lottie, 'image/webp' para WebP
|
||||||
const metadata: proto.Message.StickerPackMessage.ISticker = {
|
const metadata: proto.Message.StickerPackMessage.ISticker = {
|
||||||
fileName,
|
fileName,
|
||||||
isAnimated,
|
isAnimated,
|
||||||
emojis,
|
emojis,
|
||||||
accessibilityLabel,
|
accessibilityLabel,
|
||||||
isLottie: false,
|
isLottie,
|
||||||
mimetype: 'image/webp'
|
mimetype: isLottie ? 'application/was' : 'image/webp'
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataByHash.set(fileName, metadata)
|
metadataByHash.set(fileName, metadata)
|
||||||
@@ -636,10 +725,22 @@ export const prepareStickerPackMessage = async (
|
|||||||
logger?.trace('Processing cover image')
|
logger?.trace('Processing cover image')
|
||||||
coverBuffer = await mediaToBuffer(cover, 'cover image')
|
coverBuffer = await mediaToBuffer(cover, 'cover image')
|
||||||
|
|
||||||
// Converte cover para WebP e adiciona ao ZIP
|
// Tray icon uses PNG format, 96x96 pixels (official client standard)
|
||||||
const result = await convertToWebP(coverBuffer, logger)
|
const lib = await getImageProcessingLibrary()
|
||||||
coverWebP = result.webpBuffer
|
if (!lib?.sharp) {
|
||||||
coverFileName = `${stickerPackId}.webp`
|
throw new Boom(
|
||||||
|
'Sharp library is required for cover/tray icon processing. Install with: yarn add sharp',
|
||||||
|
{ statusCode: 400 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
coverWebP = await lib.sharp
|
||||||
|
.default(coverBuffer)
|
||||||
|
.resize(96, 96, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } })
|
||||||
|
.png()
|
||||||
|
.toBuffer()
|
||||||
|
|
||||||
|
coverFileName = `${stickerPackId}.png`
|
||||||
stickerData[coverFileName] = [new Uint8Array(coverWebP), { level: 0 as 0 }]
|
stickerData[coverFileName] = [new Uint8Array(coverWebP), { level: 0 as 0 }]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Boom(`Failed to process cover image: ${(error as Error).message}`, {
|
throw new Boom(`Failed to process cover image: ${(error as Error).message}`, {
|
||||||
|
|||||||
@@ -159,7 +159,10 @@ export async function storeTcTokensFromIqResult({
|
|||||||
[storageJid]: {
|
[storageJid]: {
|
||||||
...existingEntry,
|
...existingEntry,
|
||||||
token: Buffer.from(tokenNode.content),
|
token: Buffer.from(tokenNode.content),
|
||||||
timestamp: tokenNode.attrs.t
|
timestamp: tokenNode.attrs.t,
|
||||||
|
// WABA Android: resets real_issue_timestamp to null when storing a new token
|
||||||
|
// (UPDATE wa_trusted_contacts_send SET real_issue_timestamp=null)
|
||||||
|
realIssueTimestamp: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user