fix(core): payload size limit
This commit is contained in:
parent
df84137391
commit
cae7f90c57
2 changed files with 29 additions and 10 deletions
|
@ -1,6 +1,9 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { MaybeArray } from '@mtcute/core'
|
||||
import { createUsersChatsIndex, normalizeToInputChannel } from '../../utils/peer-utils'
|
||||
import {
|
||||
createUsersChatsIndex,
|
||||
normalizeToInputChannel,
|
||||
} from '../../utils/peer-utils'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { Message, InputPeerLike, MtCuteTypeAssertionError } from '../../types'
|
||||
|
||||
|
@ -53,16 +56,17 @@ export async function getMessages(
|
|||
const isSingle = !Array.isArray(messageIds)
|
||||
if (isSingle) messageIds = [messageIds as number]
|
||||
|
||||
const ids = (messageIds as number[]).map(
|
||||
(it) =>
|
||||
({
|
||||
_: fromReply ? 'inputMessageReplyTo' : 'inputMessageID',
|
||||
const type = fromReply ? 'inputMessageReplyTo' : 'inputMessageID'
|
||||
const ids: tl.TypeInputMessage[] = (messageIds as number[]).map((it) => ({
|
||||
_: type,
|
||||
id: it,
|
||||
} as tl.TypeInputMessage)
|
||||
)
|
||||
}))
|
||||
|
||||
const res = await this.call(
|
||||
peer._ === 'inputPeerChannel' || peer._ === 'inputChannel'
|
||||
peer._ === 'inputPeerChannel' ||
|
||||
peer._ === 'inputChannel' ||
|
||||
peer._ === 'inputPeerChannelFromMessage' ||
|
||||
peer._ === 'inputChannelFromMessage'
|
||||
? {
|
||||
_: 'channels.getMessages',
|
||||
id: ids,
|
||||
|
|
|
@ -551,6 +551,21 @@ export class TelegramConnection extends PersistentConnection {
|
|||
stack = new Error().stack
|
||||
}
|
||||
|
||||
const content = typeof method === 'string' ? message! : method.message
|
||||
if (content.length > 1044404) {
|
||||
// if you send larger payloads, telegram will just close connection,
|
||||
// and since we resend them, it will get resent after reconnection and
|
||||
// that will be an endless loop of reconnections. we don't want that,
|
||||
// and payloads this large are usually a sign of an error in the code.
|
||||
const err = new Error(`Payload is too big (${content.length} > 1044404)`)
|
||||
if (typeof method === 'string') {
|
||||
throw err
|
||||
} else {
|
||||
// shouldn't happen, but whatever
|
||||
method.promise.reject(err)
|
||||
}
|
||||
}
|
||||
|
||||
const promise =
|
||||
typeof method === 'string'
|
||||
? createControllablePromise()
|
||||
|
@ -572,7 +587,7 @@ export class TelegramConnection extends PersistentConnection {
|
|||
this._pendingRpcCalls[messageId.toString(16)] = pending
|
||||
|
||||
const encrypted = await this._mtproto.encryptMessage(
|
||||
typeof method === 'string' ? message! : method.message,
|
||||
content,
|
||||
messageId,
|
||||
seqNo
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue