teleproto 1.224.2 → 1.225.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Version.d.ts +1 -1
- package/Version.js +1 -1
- package/client/TelegramClient.d.ts +0 -26
- package/client/TelegramClient.js +2 -33
- package/client/downloads.d.ts +4 -94
- package/client/downloads.js +118 -409
- package/client/telegramBaseClient.d.ts +10 -9
- package/client/telegramBaseClient.js +45 -100
- package/network/ApiSenderPool.d.ts +30 -0
- package/network/ApiSenderPool.js +77 -0
- package/network/FilePool.d.ts +65 -0
- package/network/FilePool.js +396 -0
- package/network/MTProtoSender.d.ts +0 -2
- package/network/MTProtoSender.js +0 -18
- package/network/OrderedWriter.d.ts +24 -0
- package/network/OrderedWriter.js +65 -0
- package/network/SenderSlot.d.ts +61 -0
- package/network/SenderSlot.js +151 -0
- package/network/index.d.ts +4 -0
- package/network/index.js +15 -1
- package/package.json +1 -1
- package/sessions/Memory.d.ts +8 -1
- package/sessions/Memory.js +19 -8
- package/sessions/StoreSession.d.ts +1 -0
- package/sessions/StoreSession.js +35 -0
- package/tl/generated/api-definitions.js +1 -1
- package/tl/generated/api.d.ts +411 -14
- package/tl/runtime/registry.d.ts +1 -1
- package/tl/runtime/registry.js +1 -1
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.225.1";
|
package/Version.js
CHANGED
|
@@ -353,30 +353,6 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
353
353
|
* ```
|
|
354
354
|
*/
|
|
355
355
|
downloadFile(inputLocation: Api.TypeInputFileLocation, fileParams?: downloadMethods.DownloadFileParams): Promise<string | Buffer<ArrayBufferLike> | undefined>;
|
|
356
|
-
/**
|
|
357
|
-
* Iterates over a file download, yielding chunks of the file.
|
|
358
|
-
* This method can be used to stream files in a more convenient way, since it offers more control (pausing, resuming, etc.)
|
|
359
|
-
* @param iterFileParams - {@link IterDownloadFunction}
|
|
360
|
-
* @return a Buffer downloaded from the inputFile.
|
|
361
|
-
* @example
|
|
362
|
-
* ```ts
|
|
363
|
-
* const photo = message.photo;
|
|
364
|
-
* for await (const chunk of client.iterDownload({
|
|
365
|
-
* file: new Api.InputPhotoFileLocation({
|
|
366
|
-
* id: photo.id,
|
|
367
|
-
* accessHash: photo.accessHash,
|
|
368
|
-
* fileReference: photo.fileReference,
|
|
369
|
-
* thumbSize: size.type
|
|
370
|
-
* }),
|
|
371
|
-
* offset: start,
|
|
372
|
-
* limit: end,
|
|
373
|
-
* requestSize:2048*1024
|
|
374
|
-
* )){
|
|
375
|
-
* console.log("Downloaded chunk of size",chunk.length);
|
|
376
|
-
* };
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
iterDownload(iterFileParams: downloadMethods.IterDownloadFunction): downloadMethods.DirectDownloadIter;
|
|
380
356
|
/**
|
|
381
357
|
* Downloads the profile photo from the given user,chat or channel.<br/>
|
|
382
358
|
* This method will return an empty buffer in case of no profile photo.
|
|
@@ -1133,8 +1109,6 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
1133
1109
|
/** @hidden */
|
|
1134
1110
|
_getDownloadConcurrency(fileSize: number): Promise<number>;
|
|
1135
1111
|
/** @hidden */
|
|
1136
|
-
_removeSender(dcId: number): void;
|
|
1137
|
-
/** @hidden */
|
|
1138
1112
|
_getResponseMessage(req: any, result: any, inputChat: any): Api.TypeMessage | Map<number, Api.Message> | (Api.Message | undefined)[] | undefined;
|
|
1139
1113
|
/** @hidden */
|
|
1140
1114
|
static get events(): any;
|
package/client/TelegramClient.js
CHANGED
|
@@ -433,32 +433,6 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
433
433
|
downloadFile(inputLocation, fileParams = {}) {
|
|
434
434
|
return downloadMethods.downloadFile(this, inputLocation, fileParams);
|
|
435
435
|
}
|
|
436
|
-
/**
|
|
437
|
-
* Iterates over a file download, yielding chunks of the file.
|
|
438
|
-
* This method can be used to stream files in a more convenient way, since it offers more control (pausing, resuming, etc.)
|
|
439
|
-
* @param iterFileParams - {@link IterDownloadFunction}
|
|
440
|
-
* @return a Buffer downloaded from the inputFile.
|
|
441
|
-
* @example
|
|
442
|
-
* ```ts
|
|
443
|
-
* const photo = message.photo;
|
|
444
|
-
* for await (const chunk of client.iterDownload({
|
|
445
|
-
* file: new Api.InputPhotoFileLocation({
|
|
446
|
-
* id: photo.id,
|
|
447
|
-
* accessHash: photo.accessHash,
|
|
448
|
-
* fileReference: photo.fileReference,
|
|
449
|
-
* thumbSize: size.type
|
|
450
|
-
* }),
|
|
451
|
-
* offset: start,
|
|
452
|
-
* limit: end,
|
|
453
|
-
* requestSize:2048*1024
|
|
454
|
-
* )){
|
|
455
|
-
* console.log("Downloaded chunk of size",chunk.length);
|
|
456
|
-
* };
|
|
457
|
-
* ```
|
|
458
|
-
*/
|
|
459
|
-
iterDownload(iterFileParams) {
|
|
460
|
-
return downloadMethods.iterDownload(this, iterFileParams);
|
|
461
|
-
}
|
|
462
436
|
//region download
|
|
463
437
|
/**
|
|
464
438
|
* Downloads the profile photo from the given user,chat or channel.<br/>
|
|
@@ -1183,7 +1157,6 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
1183
1157
|
client: this,
|
|
1184
1158
|
securityChecks: this._securityChecks,
|
|
1185
1159
|
autoReconnectCallback: this._handleReconnect.bind(this),
|
|
1186
|
-
_exportedSenderPromises: this._exportedSenderPromises,
|
|
1187
1160
|
reconnectRetries: this._reconnectRetries,
|
|
1188
1161
|
});
|
|
1189
1162
|
}
|
|
@@ -1225,12 +1198,12 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
1225
1198
|
this._log.info(`Reconnecting to new data center ${newDc}`);
|
|
1226
1199
|
const DC = await this.getDC(newDc);
|
|
1227
1200
|
this.session.setDC(newDc, DC.ipAddress, DC.port);
|
|
1228
|
-
// authKey's are associated with a server, which has now changed
|
|
1229
|
-
// so it's not valid anymore. Set to undefined to force recreating it.
|
|
1230
1201
|
await this._sender.authKey.setKey(undefined);
|
|
1231
1202
|
this.session.setAuthKey(undefined);
|
|
1232
1203
|
this.session.save();
|
|
1233
1204
|
this._isSwitchingDc = true;
|
|
1205
|
+
await this._filePool.purge();
|
|
1206
|
+
await this._apiSenderPool.purge();
|
|
1234
1207
|
await this._disconnect();
|
|
1235
1208
|
this._sender = undefined;
|
|
1236
1209
|
return await this.connect();
|
|
@@ -1332,10 +1305,6 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
1332
1305
|
return fileSize > 20 * 1024 * 1024 ? largeLimit : smallLimit;
|
|
1333
1306
|
}
|
|
1334
1307
|
/** @hidden */
|
|
1335
|
-
_removeSender(dcId) {
|
|
1336
|
-
delete this._borrowedSenderPromises[dcId];
|
|
1337
|
-
}
|
|
1338
|
-
/** @hidden */
|
|
1339
1308
|
_getResponseMessage(req, result, inputChat) {
|
|
1340
1309
|
return parseMethods._getResponseMessage(this, req, result, inputChat);
|
|
1341
1310
|
}
|
package/client/downloads.d.ts
CHANGED
|
@@ -1,119 +1,29 @@
|
|
|
1
1
|
import { Api } from "../tl";
|
|
2
2
|
import type { TelegramClient } from "./TelegramClient";
|
|
3
3
|
import { EntityLike, OutFile, ProgressCallback } from "../define";
|
|
4
|
-
import { RequestIter } from "../requestIter";
|
|
5
4
|
import bigInt from "big-integer";
|
|
6
|
-
/**
|
|
7
|
-
* progress callback that will be called each time a new chunk is downloaded.
|
|
8
|
-
*/
|
|
9
5
|
export interface progressCallback {
|
|
10
|
-
(
|
|
11
|
-
/** How much was downloaded */
|
|
12
|
-
downloaded: bigInt.BigInteger,
|
|
13
|
-
/** Full size of the file to be downloaded */
|
|
14
|
-
fullSize: bigInt.BigInteger,
|
|
15
|
-
/** other args to be passed if needed */
|
|
16
|
-
...args: any[]): void;
|
|
17
|
-
/** When this value is set to true the download will stop */
|
|
6
|
+
(downloaded: bigInt.BigInteger, fullSize: bigInt.BigInteger, ...args: any[]): void;
|
|
18
7
|
isCanceled?: boolean;
|
|
19
|
-
/** Does nothing for now. */
|
|
20
8
|
acceptsBuffer?: boolean;
|
|
21
9
|
}
|
|
22
10
|
export interface DownloadFileParams {
|
|
23
|
-
/**
|
|
24
|
-
* The output file path, directory,buffer, or stream-like object.
|
|
25
|
-
* If the path exists and is a file, it will be overwritten.
|
|
26
|
-
|
|
27
|
-
* If the file path is `undefined` or `Buffer`, then the result
|
|
28
|
-
will be saved in memory and returned as `Buffer`.
|
|
29
|
-
*/
|
|
30
11
|
outputFile?: OutFile;
|
|
31
|
-
/** The dcId that the file belongs to. Used to borrow a sender from that DC. The library should handle this for you */
|
|
32
12
|
dcId?: number;
|
|
33
|
-
/** The file size that is about to be downloaded, if known.<br/>
|
|
34
|
-
Only used if ``progressCallback`` is specified. */
|
|
35
13
|
fileSize?: bigInt.BigInteger;
|
|
36
|
-
/** How much to download in each chunk. The larger the less requests to be made. (max is 512kb). */
|
|
37
14
|
partSizeKb?: number;
|
|
38
|
-
/** Progress callback accepting one param. (progress :number) which is a float between 0 and 1 */
|
|
39
15
|
progressCallback?: progressCallback;
|
|
40
16
|
msgData?: [EntityLike, number];
|
|
41
17
|
}
|
|
42
|
-
/**
|
|
43
|
-
* contains optional download params for profile photo.
|
|
44
|
-
*/
|
|
45
18
|
export interface DownloadProfilePhotoParams {
|
|
46
|
-
/** Whether to download the big version or the small one of the photo */
|
|
47
19
|
isBig?: boolean;
|
|
48
20
|
outputFile?: OutFile;
|
|
49
21
|
}
|
|
50
|
-
export interface DirectDownloadIterInterface {
|
|
51
|
-
fileLocation: Api.TypeInputFileLocation;
|
|
52
|
-
dcId: number;
|
|
53
|
-
offset: bigInt.BigInteger;
|
|
54
|
-
stride: number;
|
|
55
|
-
chunkSize: number;
|
|
56
|
-
requestSize: number;
|
|
57
|
-
fileSize: number;
|
|
58
|
-
msgData: number;
|
|
59
|
-
}
|
|
60
|
-
export interface IterDownloadFunction {
|
|
61
|
-
file?: Api.TypeMessageMedia | Api.TypeInputFile | Api.TypeInputFileLocation;
|
|
62
|
-
offset?: bigInt.BigInteger;
|
|
63
|
-
stride?: number;
|
|
64
|
-
limit?: number;
|
|
65
|
-
chunkSize?: number;
|
|
66
|
-
requestSize: number;
|
|
67
|
-
fileSize?: bigInt.BigInteger;
|
|
68
|
-
dcId?: number;
|
|
69
|
-
msgData?: [EntityLike, number];
|
|
70
|
-
}
|
|
71
|
-
export declare class DirectDownloadIter extends RequestIter {
|
|
72
|
-
protected request?: Api.upload.GetFile;
|
|
73
|
-
private _sender?;
|
|
74
|
-
private _timedOut;
|
|
75
|
-
protected _stride?: number;
|
|
76
|
-
protected _chunkSize?: number;
|
|
77
|
-
protected _lastPart?: Buffer;
|
|
78
|
-
protected buffer: Buffer[] | undefined;
|
|
79
|
-
_init({ fileLocation, dcId, offset, stride, chunkSize, requestSize, fileSize, msgData, }: DirectDownloadIterInterface): Promise<void>;
|
|
80
|
-
_loadNextChunk(): Promise<boolean | undefined>;
|
|
81
|
-
_request(): Promise<Buffer>;
|
|
82
|
-
close(): Promise<void>;
|
|
83
|
-
[Symbol.asyncIterator](): AsyncIterator<Buffer, any, undefined>;
|
|
84
|
-
}
|
|
85
|
-
export declare class GenericDownloadIter extends DirectDownloadIter {
|
|
86
|
-
_loadNextChunk(): Promise<boolean | undefined>;
|
|
87
|
-
}
|
|
88
|
-
/** @hidden */
|
|
89
|
-
export declare function iterDownload(client: TelegramClient, { file, offset, stride, limit, chunkSize, requestSize, fileSize, dcId, msgData, }: IterDownloadFunction): DirectDownloadIter;
|
|
90
22
|
/** @hidden */
|
|
91
|
-
export declare function downloadFile(client: TelegramClient, inputLocation: Api.TypeInputFileLocation, { outputFile, partSizeKb, fileSize, progressCallback, dcId,
|
|
92
|
-
/**
|
|
93
|
-
* All of these are optional and will be calculated automatically if not specified.
|
|
94
|
-
*/
|
|
23
|
+
export declare function downloadFile(client: TelegramClient, inputLocation: Api.TypeInputFileLocation, { outputFile, partSizeKb, fileSize, progressCallback, dcId, }: DownloadFileParams): Promise<Buffer | string | undefined>;
|
|
95
24
|
export interface DownloadMediaInterface {
|
|
96
|
-
/**
|
|
97
|
-
* The output file location, if left undefined this method will return a buffer
|
|
98
|
-
*/
|
|
99
25
|
outputFile?: OutFile;
|
|
100
|
-
/**
|
|
101
|
-
* Which thumbnail size from the document or photo to download, instead of downloading the document or photo itself.<br/>
|
|
102
|
-
<br/>
|
|
103
|
-
If it's specified but the file does not have a thumbnail, this method will return `undefined`.<br/>
|
|
104
|
-
<br/>
|
|
105
|
-
The parameter should be an integer index between ``0`` and ``sizes.length``.<br/>
|
|
106
|
-
``0`` will download the smallest thumbnail, and ``sizes.length - 1`` will download the largest thumbnail.<br/>
|
|
107
|
-
<br/>
|
|
108
|
-
You can also pass the `Api.PhotoSize` instance to use. Alternatively, the thumb size type `string` may be used.<br/>
|
|
109
|
-
<br/>
|
|
110
|
-
In short, use ``thumb=0`` if you want the smallest thumbnail and ``thumb=sizes.length`` if you want the largest thumbnail.
|
|
111
|
-
*/
|
|
112
26
|
thumb?: number | Api.TypePhotoSize;
|
|
113
|
-
/**
|
|
114
|
-
* A callback function accepting two parameters:
|
|
115
|
-
* ``(received bytes, total)``.
|
|
116
|
-
*/
|
|
117
27
|
progressCallback?: ProgressCallback;
|
|
118
28
|
}
|
|
119
29
|
/** @hidden */
|
|
@@ -121,9 +31,9 @@ export declare function downloadMedia(client: TelegramClient, messageOrMedia: Ap
|
|
|
121
31
|
/** @hidden */
|
|
122
32
|
export declare function _downloadDocument(client: TelegramClient, doc: Api.MessageMediaDocument | Api.TypeDocument, outputFile: OutFile | undefined, date: number, thumb?: number | string | Api.TypePhotoSize, progressCallback?: ProgressCallback, msgData?: [EntityLike, number]): Promise<Buffer | string | undefined>;
|
|
123
33
|
/** @hidden */
|
|
124
|
-
export declare function _downloadContact(
|
|
34
|
+
export declare function _downloadContact(_client: TelegramClient, _media: Api.MessageMediaContact, _args: DownloadMediaInterface): Promise<Buffer>;
|
|
125
35
|
/** @hidden */
|
|
126
|
-
export declare function _downloadWebDocument(
|
|
36
|
+
export declare function _downloadWebDocument(_client: TelegramClient, _media: Api.WebDocument | Api.WebDocumentNoProxy, _args: DownloadMediaInterface): Promise<Buffer>;
|
|
127
37
|
/** @hidden */
|
|
128
38
|
export declare function _downloadCachedPhotoSize(size: Api.PhotoCachedSize | Api.PhotoStrippedSize, outputFile?: OutFile): Promise<string | Buffer<ArrayBufferLike> | undefined>;
|
|
129
39
|
/** @hidden */
|