@mtkruto/node 0.0.906 → 0.0.920
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/esm/{types/utilities → client}/0_html.d.ts +1 -1
- package/esm/{types/utilities → client}/0_html.js +2 -2
- package/esm/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
- package/esm/client/{utilities/0_message.js → 0_message.js} +10 -10
- package/esm/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
- package/esm/client/{utilities/0_password.js → 0_password.js} +5 -5
- package/{script/client/client_abstract.d.ts → esm/client/1_client_abstract.d.ts} +6 -5
- package/esm/client/{client_abstract.js → 1_client_abstract.js} +10 -4
- package/esm/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
- package/esm/client/{client_plain.js → 2_client_plain.js} +2 -2
- package/esm/client/{client.d.ts → 3_client.d.ts} +7 -5
- package/esm/client/{client.js → 3_client.js} +145 -83
- package/{script/connection/connection_web_socket.d.ts → esm/connection/1_connection_web_socket.d.ts} +1 -1
- package/esm/constants.d.ts +2 -2
- package/esm/constants.js +1 -1
- package/esm/deps.d.ts +1 -2
- package/esm/deps.js +0 -1
- package/esm/mod.d.ts +13 -13
- package/esm/mod.js +13 -13
- package/esm/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
- package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts} +1 -1
- package/esm/storage/{storage_local_storage.js → 1_storage_local_storage.js} +1 -1
- package/{script/storage/storage_memory.d.ts → esm/storage/1_storage_memory.d.ts} +1 -1
- package/esm/storage/{storage_memory.js → 1_storage_memory.js} +1 -1
- package/esm/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
- package/esm/storage/{storage_session_storage.js → 1_storage_session_storage.js} +1 -1
- package/esm/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
- package/esm/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
- package/esm/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
- package/esm/transport/{transport_abridged.js → 1_transport_abridged.js} +2 -2
- package/esm/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
- package/esm/transport/{transport_intermediate.js → 1_transport_intermediate.js} +2 -2
- package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts} +2 -2
- package/esm/transport/{transport_provider.js → 2_transport_provider.js} +2 -2
- package/esm/types/!0_file_id.d.ts +77 -0
- package/esm/types/!0_file_id.js +325 -0
- package/esm/types/0_chat_photo.d.ts +7 -14
- package/esm/types/0_chat_photo.js +32 -17
- package/esm/types/1_chat.js +4 -4
- package/esm/types/1_user.js +2 -2
- package/esm/types/3_message.js +9 -0
- package/esm/utilities/0_base64.d.ts +2 -0
- package/esm/utilities/0_base64.js +9 -0
- package/esm/utilities/0_rle.d.ts +2 -0
- package/esm/utilities/0_rle.js +49 -0
- package/package.json +1 -1
- package/script/{types/utilities → client}/0_html.d.ts +1 -1
- package/script/{types/utilities → client}/0_html.js +2 -2
- package/script/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
- package/script/client/{utilities/0_message.js → 0_message.js} +10 -10
- package/script/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
- package/script/client/{utilities/0_password.js → 0_password.js} +5 -5
- package/script/client/0_password_test.d.ts +1 -0
- package/{esm/client/client_abstract.d.ts → script/client/1_client_abstract.d.ts} +6 -5
- package/script/client/{client_abstract.js → 1_client_abstract.js} +10 -4
- package/script/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
- package/script/client/{client_plain.js → 2_client_plain.js} +3 -3
- package/script/client/{client.d.ts → 3_client.d.ts} +7 -5
- package/script/client/{client.js → 3_client.js} +146 -84
- package/{esm/connection/connection_web_socket.d.ts → script/connection/1_connection_web_socket.d.ts} +1 -1
- package/script/constants.d.ts +2 -2
- package/script/constants.js +1 -1
- package/script/deps.d.ts +1 -2
- package/script/deps.js +1 -3
- package/script/mod.d.ts +13 -13
- package/script/mod.js +13 -13
- package/script/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
- package/{esm/storage/storage_local_storage.d.ts → script/storage/1_storage_local_storage.d.ts} +1 -1
- package/script/storage/{storage_local_storage.js → 1_storage_local_storage.js} +2 -2
- package/{esm/storage/storage_memory.d.ts → script/storage/1_storage_memory.d.ts} +1 -1
- package/script/storage/{storage_memory.js → 1_storage_memory.js} +2 -2
- package/script/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
- package/script/storage/{storage_session_storage.js → 1_storage_session_storage.js} +2 -2
- package/script/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
- package/script/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
- package/script/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
- package/script/transport/{transport_abridged.js → 1_transport_abridged.js} +3 -3
- package/script/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
- package/script/transport/{transport_intermediate.js → 1_transport_intermediate.js} +3 -3
- package/{esm/transport/transport_provider.d.ts → script/transport/2_transport_provider.d.ts} +2 -2
- package/script/transport/{transport_provider.js → 2_transport_provider.js} +4 -4
- package/script/types/!0_file_id.d.ts +77 -0
- package/script/types/!0_file_id.js +329 -0
- package/script/types/0_chat_photo.d.ts +7 -14
- package/script/types/0_chat_photo.js +33 -18
- package/script/types/1_chat.js +4 -4
- package/script/types/1_user.js +2 -2
- package/script/types/3_message.js +9 -0
- package/script/utilities/0_base64.d.ts +2 -0
- package/script/utilities/0_base64.js +14 -0
- package/script/utilities/0_rle.d.ts +2 -0
- package/script/utilities/0_rle.js +54 -0
- package/script/utilities/0_rle_test.d.ts +1 -0
- package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
- package/esm/deps/deno.land/x/q@v0.0.1/mod.js +0 -71
- package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
- package/script/deps/deno.land/x/q@v0.0.1/mod.js +0 -75
- /package/esm/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
- /package/esm/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
- /package/esm/connection/{connection.js → 0_connection.js} +0 -0
- /package/esm/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
- /package/esm/storage/{storage.js → 0_storage.js} +0 -0
- /package/esm/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
- /package/esm/transport/{transport.js → 0_transport.js} +0 -0
- /package/esm/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
- /package/esm/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
- /package/{script/client/utilities/0_password_test.d.ts → esm/utilities/0_rle_test.d.ts} +0 -0
- /package/script/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
- /package/script/connection/{connection.js → 0_connection.js} +0 -0
- /package/script/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
- /package/script/storage/{storage.js → 0_storage.js} +0 -0
- /package/script/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
- /package/script/transport/{transport.js → 0_transport.js} +0 -0
- /package/script/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
- /package/script/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
package/esm/mod.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getRandomId } from "./utilities/0_bigint.js";
|
|
2
|
-
import { checkPassword } from "./client/
|
|
2
|
+
import { checkPassword } from "./client/0_password.js";
|
|
3
3
|
export const utils = { checkPassword, getRandomId };
|
|
4
4
|
export { as } from "./tl/1_tl_object.js";
|
|
5
5
|
export * as types from "./tl/2_types.js";
|
|
@@ -7,16 +7,16 @@ export * as functions from "./tl/3_functions.js";
|
|
|
7
7
|
export * from "./tl/5_rpc_result.js";
|
|
8
8
|
export * from "./tl/6_message.js";
|
|
9
9
|
export * from "./tl/7_message_container.js";
|
|
10
|
-
export * from "./client/
|
|
11
|
-
export * from "./client/
|
|
12
|
-
export * from "./storage/
|
|
13
|
-
export * from "./storage/
|
|
14
|
-
export * from "./storage/
|
|
15
|
-
export * from "./storage/
|
|
16
|
-
export * from "./transport/
|
|
17
|
-
export * from "./transport/
|
|
18
|
-
export * from "./transport/
|
|
19
|
-
export * from "./transport/
|
|
20
|
-
export * from "./connection/
|
|
21
|
-
export * from "./connection/
|
|
10
|
+
export * from "./client/2_client_plain.js";
|
|
11
|
+
export * from "./client/3_client.js";
|
|
12
|
+
export * from "./storage/0_storage.js";
|
|
13
|
+
export * from "./storage/1_storage_memory.js";
|
|
14
|
+
export * from "./storage/1_storage_local_storage.js";
|
|
15
|
+
export * from "./storage/1_storage_session_storage.js";
|
|
16
|
+
export * from "./transport/1_transport_abridged.js";
|
|
17
|
+
export * from "./transport/1_transport_intermediate.js";
|
|
18
|
+
export * from "./transport/0_transport.js";
|
|
19
|
+
export * from "./transport/2_transport_provider.js";
|
|
20
|
+
export * from "./connection/0_connection.js";
|
|
21
|
+
export * from "./connection/1_connection_web_socket.js";
|
|
22
22
|
export { DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_INITIAL_DC, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER } from "./constants.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
-
import { DC } from "../transport/
|
|
2
|
+
import { DC } from "../transport/2_transport_provider.js";
|
|
3
3
|
import * as types from "../tl/2_types.js";
|
|
4
4
|
export declare abstract class Storage {
|
|
5
5
|
private _authKeyId;
|
package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
-
import { Storage } from "./
|
|
2
|
+
import { Storage } from "./0_storage.js";
|
|
3
3
|
export declare class StorageLocalStorage extends Storage implements Storage {
|
|
4
4
|
private readonly prefix;
|
|
5
5
|
constructor(prefix: string);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
-
import { Storage } from "./
|
|
2
|
+
import { Storage } from "./0_storage.js";
|
|
3
3
|
export declare class StorageSessionStorage extends Storage implements Storage {
|
|
4
4
|
private readonly prefix;
|
|
5
5
|
constructor(prefix: string);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CTR } from "
|
|
2
|
-
import { Connection } from "
|
|
1
|
+
import { CTR } from "../utilities/0_crypto.js";
|
|
2
|
+
import { Connection } from "../connection/0_connection.js";
|
|
3
3
|
export declare function getObfuscationParameters(protocol: number, connection: Connection): Promise<{
|
|
4
4
|
encryptionCTR: CTR;
|
|
5
5
|
decryptionCTR: CTR;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as dntShim from "
|
|
2
|
-
import { bufferFromBigInt, concat } from "
|
|
3
|
-
import { CTR } from "
|
|
1
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
2
|
+
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
3
|
+
import { CTR } from "../utilities/0_crypto.js";
|
|
4
4
|
export async function getObfuscationParameters(protocol, connection) {
|
|
5
5
|
const dc = 0xFCFF;
|
|
6
6
|
let init;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection } from "../connection/
|
|
2
|
-
import { Transport } from "./
|
|
1
|
+
import { Connection } from "../connection/0_connection.js";
|
|
2
|
+
import { Transport } from "./0_transport.js";
|
|
3
3
|
export declare class TransportAbridged extends Transport implements Transport {
|
|
4
4
|
private readonly connection;
|
|
5
5
|
private readonly obfuscated;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
2
|
-
import { getObfuscationParameters } from "./
|
|
3
|
-
import { Transport } from "./
|
|
2
|
+
import { getObfuscationParameters } from "./0_obfuscation.js";
|
|
3
|
+
import { Transport } from "./0_transport.js";
|
|
4
4
|
export class TransportAbridged extends Transport {
|
|
5
5
|
constructor(connection, obfuscated = false) {
|
|
6
6
|
super();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection } from "../connection/
|
|
2
|
-
import { Transport } from "./
|
|
1
|
+
import { Connection } from "../connection/0_connection.js";
|
|
2
|
+
import { Transport } from "./0_transport.js";
|
|
3
3
|
export declare class TransportIntermediate extends Transport implements Transport {
|
|
4
4
|
private readonly connection;
|
|
5
5
|
private readonly obfuscated;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { bufferFromBigInt, concat } from "../utilities/0_buffer.js";
|
|
2
|
-
import { getObfuscationParameters } from "./
|
|
3
|
-
import { Transport } from "./
|
|
2
|
+
import { getObfuscationParameters } from "./0_obfuscation.js";
|
|
3
|
+
import { Transport } from "./0_transport.js";
|
|
4
4
|
export class TransportIntermediate extends Transport {
|
|
5
5
|
constructor(connection, obfuscated = false) {
|
|
6
6
|
super();
|
package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Connection } from "../connection/
|
|
2
|
-
import { Transport } from "./
|
|
1
|
+
import { Connection } from "../connection/0_connection.js";
|
|
2
|
+
import { Transport } from "./0_transport.js";
|
|
3
3
|
export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
|
|
4
4
|
export interface TransportProviderParams {
|
|
5
5
|
dc?: DC;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConnectionWebSocket } from "../connection/
|
|
2
|
-
import { TransportIntermediate } from "./
|
|
1
|
+
import { ConnectionWebSocket } from "../connection/1_connection_web_socket.js";
|
|
2
|
+
import { TransportIntermediate } from "./1_transport_intermediate.js";
|
|
3
3
|
const dcToNameMap = {
|
|
4
4
|
"1": "pluto",
|
|
5
5
|
"1-test": "pluto",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare enum FileType {
|
|
2
|
+
Thumbnail = 0,
|
|
3
|
+
ChatPhoto = 1,
|
|
4
|
+
Photo = 2,
|
|
5
|
+
Voice = 3,
|
|
6
|
+
Video = 4,
|
|
7
|
+
Document = 5,
|
|
8
|
+
Encrypted = 6,
|
|
9
|
+
Temp = 7,
|
|
10
|
+
Sticker = 8,
|
|
11
|
+
Audio = 9,
|
|
12
|
+
Animation = 10,
|
|
13
|
+
EncryptedThumbnail = 11,
|
|
14
|
+
Wallpaper = 12,
|
|
15
|
+
VideoNote = 13,
|
|
16
|
+
SecureRaw = 14,
|
|
17
|
+
Secure = 15,
|
|
18
|
+
Background = 16,
|
|
19
|
+
DocumentAsFile = 17
|
|
20
|
+
}
|
|
21
|
+
export declare enum ThumbnailSource {
|
|
22
|
+
Legacy = 0,
|
|
23
|
+
Thumbnail = 1,
|
|
24
|
+
ChatPhotoSmall = 2,
|
|
25
|
+
ChatPhotoBig = 3,
|
|
26
|
+
StickerSetThumbnail = 4
|
|
27
|
+
}
|
|
28
|
+
interface FileIDParams {
|
|
29
|
+
fileReference?: Uint8Array;
|
|
30
|
+
url?: string;
|
|
31
|
+
mediaId?: bigint;
|
|
32
|
+
accessHash?: bigint;
|
|
33
|
+
volumeId?: bigint;
|
|
34
|
+
thumbnailSource?: ThumbnailSource;
|
|
35
|
+
thumbnailFileType?: FileType;
|
|
36
|
+
thumbnailSize?: string;
|
|
37
|
+
secret?: bigint;
|
|
38
|
+
localId?: number;
|
|
39
|
+
chatId?: number;
|
|
40
|
+
chatAccessHash?: bigint;
|
|
41
|
+
stickerSetId?: bigint;
|
|
42
|
+
stickerSetAccessHash?: bigint;
|
|
43
|
+
}
|
|
44
|
+
export declare class FileID {
|
|
45
|
+
readonly fileType: FileType;
|
|
46
|
+
readonly dcId: number;
|
|
47
|
+
readonly params: FileIDParams;
|
|
48
|
+
static MAJOR: number;
|
|
49
|
+
static MINOR: number;
|
|
50
|
+
readonly major: number;
|
|
51
|
+
readonly minor: number;
|
|
52
|
+
constructor(major: number | null | undefined, minor: number | null | undefined, fileType: FileType, dcId: number, params: FileIDParams);
|
|
53
|
+
static decode(fileId: string): FileID;
|
|
54
|
+
encode(major?: number, minor?: number): string;
|
|
55
|
+
}
|
|
56
|
+
export declare enum FileUniqueType {
|
|
57
|
+
Web = 0,
|
|
58
|
+
Photo = 1,
|
|
59
|
+
Document = 2,
|
|
60
|
+
Secure = 3,
|
|
61
|
+
Encrypted = 4,
|
|
62
|
+
Temp = 5
|
|
63
|
+
}
|
|
64
|
+
interface FileUniqueParams {
|
|
65
|
+
url?: string;
|
|
66
|
+
mediaId?: bigint;
|
|
67
|
+
volumeId?: bigint;
|
|
68
|
+
localId?: number;
|
|
69
|
+
}
|
|
70
|
+
export declare class FileUniqueID {
|
|
71
|
+
private readonly fileUniqueType;
|
|
72
|
+
private readonly params;
|
|
73
|
+
constructor(fileUniqueType: FileUniqueType, params: FileUniqueParams);
|
|
74
|
+
static decode(fileId: string): FileUniqueID;
|
|
75
|
+
encode(): string;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
// Direct port from Pyrogram
|
|
2
|
+
import { base64DecodeUrlSafe, base64EncodeUrlSafe } from "../utilities/0_base64.js";
|
|
3
|
+
import { UNREACHABLE } from "../utilities/0_control.js";
|
|
4
|
+
import { rleDecode, rleEncode } from "../utilities/0_rle.js";
|
|
5
|
+
import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
|
|
6
|
+
import { TLRawReader } from "../tl/0_tl_raw_reader.js";
|
|
7
|
+
export var FileType;
|
|
8
|
+
(function (FileType) {
|
|
9
|
+
FileType[FileType["Thumbnail"] = 0] = "Thumbnail";
|
|
10
|
+
FileType[FileType["ChatPhoto"] = 1] = "ChatPhoto";
|
|
11
|
+
FileType[FileType["Photo"] = 2] = "Photo";
|
|
12
|
+
FileType[FileType["Voice"] = 3] = "Voice";
|
|
13
|
+
FileType[FileType["Video"] = 4] = "Video";
|
|
14
|
+
FileType[FileType["Document"] = 5] = "Document";
|
|
15
|
+
FileType[FileType["Encrypted"] = 6] = "Encrypted";
|
|
16
|
+
FileType[FileType["Temp"] = 7] = "Temp";
|
|
17
|
+
FileType[FileType["Sticker"] = 8] = "Sticker";
|
|
18
|
+
FileType[FileType["Audio"] = 9] = "Audio";
|
|
19
|
+
FileType[FileType["Animation"] = 10] = "Animation";
|
|
20
|
+
FileType[FileType["EncryptedThumbnail"] = 11] = "EncryptedThumbnail";
|
|
21
|
+
FileType[FileType["Wallpaper"] = 12] = "Wallpaper";
|
|
22
|
+
FileType[FileType["VideoNote"] = 13] = "VideoNote";
|
|
23
|
+
FileType[FileType["SecureRaw"] = 14] = "SecureRaw";
|
|
24
|
+
FileType[FileType["Secure"] = 15] = "Secure";
|
|
25
|
+
FileType[FileType["Background"] = 16] = "Background";
|
|
26
|
+
FileType[FileType["DocumentAsFile"] = 17] = "DocumentAsFile";
|
|
27
|
+
})(FileType || (FileType = {}));
|
|
28
|
+
const PHOTO_TYPES = [FileType.Thumbnail, FileType.ChatPhoto, FileType.Photo, FileType.EncryptedThumbnail];
|
|
29
|
+
const DOCUMENT_TYPES = Object.keys(FileType).map(Number).filter((v) => !isNaN(v)).filter((v) => !PHOTO_TYPES.includes(v));
|
|
30
|
+
export var ThumbnailSource;
|
|
31
|
+
(function (ThumbnailSource) {
|
|
32
|
+
ThumbnailSource[ThumbnailSource["Legacy"] = 0] = "Legacy";
|
|
33
|
+
ThumbnailSource[ThumbnailSource["Thumbnail"] = 1] = "Thumbnail";
|
|
34
|
+
ThumbnailSource[ThumbnailSource["ChatPhotoSmall"] = 2] = "ChatPhotoSmall";
|
|
35
|
+
ThumbnailSource[ThumbnailSource["ChatPhotoBig"] = 3] = "ChatPhotoBig";
|
|
36
|
+
ThumbnailSource[ThumbnailSource["StickerSetThumbnail"] = 4] = "StickerSetThumbnail";
|
|
37
|
+
})(ThumbnailSource || (ThumbnailSource = {}));
|
|
38
|
+
const WEB_LOCATION_FLAG = 1 << 24;
|
|
39
|
+
const FILE_REFERENCE_FLAG = 1 << 25;
|
|
40
|
+
class FileID {
|
|
41
|
+
constructor(major = FileID.MAJOR, minor = FileID.MINOR, fileType, dcId, params) {
|
|
42
|
+
Object.defineProperty(this, "fileType", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: fileType
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(this, "dcId", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: dcId
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(this, "params", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: params
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(this, "major", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: void 0
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(this, "minor", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
if (major == null) {
|
|
73
|
+
this.major = FileID.MAJOR;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.major = major;
|
|
77
|
+
}
|
|
78
|
+
if (minor == null) {
|
|
79
|
+
this.minor = FileID.MINOR;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.minor = minor;
|
|
83
|
+
}
|
|
84
|
+
this.params.thumbnailSize ??= "";
|
|
85
|
+
}
|
|
86
|
+
static decode(fileId) {
|
|
87
|
+
const decoded = rleDecode(base64DecodeUrlSafe(fileId));
|
|
88
|
+
const major = decoded[decoded.length - 1];
|
|
89
|
+
let minor;
|
|
90
|
+
let buffer;
|
|
91
|
+
if (major < 4) {
|
|
92
|
+
minor = 0;
|
|
93
|
+
buffer = decoded.slice(0, -1);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
minor = decoded[decoded.length - 2];
|
|
97
|
+
buffer = decoded.slice(0, -2);
|
|
98
|
+
}
|
|
99
|
+
const reader = new TLRawReader(buffer);
|
|
100
|
+
let fileType = reader.readInt32();
|
|
101
|
+
const dcId = reader.readInt32();
|
|
102
|
+
const hasWebLocation = Boolean(fileType & WEB_LOCATION_FLAG);
|
|
103
|
+
const hasFileReference = Boolean(fileType & FILE_REFERENCE_FLAG);
|
|
104
|
+
fileType &= ~WEB_LOCATION_FLAG;
|
|
105
|
+
fileType &= ~FILE_REFERENCE_FLAG;
|
|
106
|
+
if (hasWebLocation) {
|
|
107
|
+
const url = reader.readString();
|
|
108
|
+
const accessHash = reader.readInt64();
|
|
109
|
+
return new FileID(major, minor, fileType, dcId, { url, accessHash });
|
|
110
|
+
}
|
|
111
|
+
let fileReference = new Uint8Array();
|
|
112
|
+
if (hasFileReference) {
|
|
113
|
+
fileReference = reader.readBytes();
|
|
114
|
+
}
|
|
115
|
+
const mediaId = reader.readInt64();
|
|
116
|
+
const accessHash = reader.readInt64();
|
|
117
|
+
if (PHOTO_TYPES.includes(fileType)) {
|
|
118
|
+
const volumeId = reader.readInt64();
|
|
119
|
+
let thumbnailSource = 0;
|
|
120
|
+
if (major >= 4) {
|
|
121
|
+
thumbnailSource = reader.readInt32(false);
|
|
122
|
+
}
|
|
123
|
+
switch (thumbnailSource) {
|
|
124
|
+
case ThumbnailSource.Legacy: {
|
|
125
|
+
const secret = reader.readInt64();
|
|
126
|
+
const localId = reader.readInt32();
|
|
127
|
+
return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, secret, localId });
|
|
128
|
+
}
|
|
129
|
+
case ThumbnailSource.Thumbnail: {
|
|
130
|
+
const thumbnailFileType = reader.readInt32();
|
|
131
|
+
const thumbnailSize = String.fromCharCode(reader.readInt32());
|
|
132
|
+
const localId = reader.readInt32();
|
|
133
|
+
return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, thumbnailFileType, thumbnailSize, localId });
|
|
134
|
+
}
|
|
135
|
+
case ThumbnailSource.ChatPhotoSmall:
|
|
136
|
+
case ThumbnailSource.ChatPhotoBig: {
|
|
137
|
+
const chatId = Number(reader.readInt64());
|
|
138
|
+
const chatAccessHash = reader.readInt64();
|
|
139
|
+
const localId = reader.readInt32();
|
|
140
|
+
return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, chatId: Number(chatId), chatAccessHash, localId });
|
|
141
|
+
}
|
|
142
|
+
case ThumbnailSource.StickerSetThumbnail: {
|
|
143
|
+
const stickerSetId = reader.readInt64();
|
|
144
|
+
const stickerSetAccessHash = reader.readInt64();
|
|
145
|
+
const localId = reader.readInt32();
|
|
146
|
+
return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, stickerSetId, stickerSetAccessHash, localId });
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
UNREACHABLE();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else if (DOCUMENT_TYPES.includes(fileType)) {
|
|
153
|
+
return new FileID(minor, major, fileType, dcId, { fileReference, mediaId, accessHash });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
UNREACHABLE();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
encode(major, minor) {
|
|
160
|
+
major ??= this.major;
|
|
161
|
+
minor ??= this.minor;
|
|
162
|
+
const writer = new TLRawWriter();
|
|
163
|
+
let fileType = this.fileType;
|
|
164
|
+
if (this.params.url) {
|
|
165
|
+
fileType |= WEB_LOCATION_FLAG;
|
|
166
|
+
}
|
|
167
|
+
if (this.params.fileReference) {
|
|
168
|
+
fileType |= FILE_REFERENCE_FLAG;
|
|
169
|
+
}
|
|
170
|
+
writer.writeInt32(fileType);
|
|
171
|
+
writer.writeInt32(this.dcId);
|
|
172
|
+
if (this.params.url) {
|
|
173
|
+
writer.writeString(this.params.url);
|
|
174
|
+
}
|
|
175
|
+
if (this.params.fileReference) {
|
|
176
|
+
writer.writeBytes(this.params.fileReference);
|
|
177
|
+
}
|
|
178
|
+
if (this.params.mediaId == undefined || this.params.accessHash == undefined) {
|
|
179
|
+
UNREACHABLE();
|
|
180
|
+
}
|
|
181
|
+
writer.writeInt64(this.params.mediaId);
|
|
182
|
+
writer.writeInt64(this.params.accessHash);
|
|
183
|
+
if (PHOTO_TYPES.includes(this.fileType)) {
|
|
184
|
+
if (this.params.volumeId == undefined || this.params.thumbnailSize == undefined || this.params.localId == undefined) {
|
|
185
|
+
UNREACHABLE();
|
|
186
|
+
}
|
|
187
|
+
writer.writeInt64(this.params.volumeId);
|
|
188
|
+
if (major >= 4) {
|
|
189
|
+
writer.writeInt32(Number(this.params.thumbnailSource));
|
|
190
|
+
}
|
|
191
|
+
switch (this.params.thumbnailSource) {
|
|
192
|
+
case ThumbnailSource.Legacy:
|
|
193
|
+
if (this.params.secret == undefined) {
|
|
194
|
+
UNREACHABLE();
|
|
195
|
+
}
|
|
196
|
+
writer.writeInt64(this.params.secret);
|
|
197
|
+
writer.writeInt32(this.params.localId);
|
|
198
|
+
break;
|
|
199
|
+
case ThumbnailSource.Thumbnail:
|
|
200
|
+
if (this.params.thumbnailFileType == undefined || this.params.thumbnailSize == undefined) {
|
|
201
|
+
UNREACHABLE();
|
|
202
|
+
}
|
|
203
|
+
writer.writeInt32(Number(this.params.thumbnailFileType));
|
|
204
|
+
writer.writeInt32(this.params.thumbnailSize.charCodeAt(0));
|
|
205
|
+
writer.writeInt32(this.params.localId);
|
|
206
|
+
break;
|
|
207
|
+
case ThumbnailSource.ChatPhotoSmall:
|
|
208
|
+
case ThumbnailSource.ChatPhotoBig:
|
|
209
|
+
if (this.params.chatId == undefined || this.params.chatAccessHash == undefined) {
|
|
210
|
+
UNREACHABLE();
|
|
211
|
+
}
|
|
212
|
+
writer.writeInt64(BigInt(this.params.chatId));
|
|
213
|
+
writer.writeInt64(this.params.chatAccessHash);
|
|
214
|
+
writer.writeInt32(this.params.localId);
|
|
215
|
+
break;
|
|
216
|
+
case ThumbnailSource.StickerSetThumbnail:
|
|
217
|
+
if (this.params.stickerSetId == undefined || this.params.stickerSetAccessHash == undefined) {
|
|
218
|
+
UNREACHABLE();
|
|
219
|
+
}
|
|
220
|
+
writer.writeInt64(this.params.stickerSetId);
|
|
221
|
+
writer.writeInt64(this.params.stickerSetAccessHash);
|
|
222
|
+
writer.writeInt32(this.params.localId);
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
UNREACHABLE();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (DOCUMENT_TYPES.includes(this.fileType)) {
|
|
229
|
+
writer.writeInt32(minor);
|
|
230
|
+
writer.writeInt32(major);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
UNREACHABLE();
|
|
234
|
+
}
|
|
235
|
+
writer.write(new Uint8Array([minor, major]));
|
|
236
|
+
return base64EncodeUrlSafe(rleEncode(writer.buffer));
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
Object.defineProperty(FileID, "MAJOR", {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
configurable: true,
|
|
242
|
+
writable: true,
|
|
243
|
+
value: 4
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(FileID, "MINOR", {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
configurable: true,
|
|
248
|
+
writable: true,
|
|
249
|
+
value: 30
|
|
250
|
+
});
|
|
251
|
+
export { FileID };
|
|
252
|
+
export var FileUniqueType;
|
|
253
|
+
(function (FileUniqueType) {
|
|
254
|
+
FileUniqueType[FileUniqueType["Web"] = 0] = "Web";
|
|
255
|
+
FileUniqueType[FileUniqueType["Photo"] = 1] = "Photo";
|
|
256
|
+
FileUniqueType[FileUniqueType["Document"] = 2] = "Document";
|
|
257
|
+
FileUniqueType[FileUniqueType["Secure"] = 3] = "Secure";
|
|
258
|
+
FileUniqueType[FileUniqueType["Encrypted"] = 4] = "Encrypted";
|
|
259
|
+
FileUniqueType[FileUniqueType["Temp"] = 5] = "Temp";
|
|
260
|
+
})(FileUniqueType || (FileUniqueType = {}));
|
|
261
|
+
export class FileUniqueID {
|
|
262
|
+
constructor(fileUniqueType, params) {
|
|
263
|
+
Object.defineProperty(this, "fileUniqueType", {
|
|
264
|
+
enumerable: true,
|
|
265
|
+
configurable: true,
|
|
266
|
+
writable: true,
|
|
267
|
+
value: fileUniqueType
|
|
268
|
+
});
|
|
269
|
+
Object.defineProperty(this, "params", {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
configurable: true,
|
|
272
|
+
writable: true,
|
|
273
|
+
value: params
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
static decode(fileId) {
|
|
277
|
+
const reader = new TLRawReader(rleDecode(base64DecodeUrlSafe(fileId)));
|
|
278
|
+
const fileUniqueType = reader.readInt32();
|
|
279
|
+
switch (fileUniqueType) {
|
|
280
|
+
case FileUniqueType.Web: {
|
|
281
|
+
const url = reader.readString();
|
|
282
|
+
return new FileUniqueID(fileUniqueType, { url });
|
|
283
|
+
}
|
|
284
|
+
case FileUniqueType.Photo: {
|
|
285
|
+
const volumeId = reader.readInt64();
|
|
286
|
+
const localId = reader.readInt32();
|
|
287
|
+
return new FileUniqueID(fileUniqueType, { volumeId, localId });
|
|
288
|
+
}
|
|
289
|
+
case FileUniqueType.Document: {
|
|
290
|
+
const mediaId = reader.readInt64();
|
|
291
|
+
return new FileUniqueID(fileUniqueType, { mediaId });
|
|
292
|
+
}
|
|
293
|
+
default:
|
|
294
|
+
UNREACHABLE();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
encode() {
|
|
298
|
+
const writer = new TLRawWriter();
|
|
299
|
+
writer.writeInt32(this.fileUniqueType);
|
|
300
|
+
switch (this.fileUniqueType) {
|
|
301
|
+
case FileUniqueType.Web:
|
|
302
|
+
if (this.params.url == undefined) {
|
|
303
|
+
UNREACHABLE();
|
|
304
|
+
}
|
|
305
|
+
writer.writeString(this.params.url);
|
|
306
|
+
break;
|
|
307
|
+
case FileUniqueType.Photo:
|
|
308
|
+
if (this.params.volumeId == undefined || this.params.localId == undefined) {
|
|
309
|
+
UNREACHABLE();
|
|
310
|
+
}
|
|
311
|
+
writer.writeInt64(this.params.volumeId);
|
|
312
|
+
writer.writeInt32(this.params.localId);
|
|
313
|
+
break;
|
|
314
|
+
case FileUniqueType.Document:
|
|
315
|
+
if (this.params.mediaId == undefined) {
|
|
316
|
+
UNREACHABLE();
|
|
317
|
+
}
|
|
318
|
+
writer.writeInt64(this.params.mediaId);
|
|
319
|
+
break;
|
|
320
|
+
default:
|
|
321
|
+
UNREACHABLE();
|
|
322
|
+
}
|
|
323
|
+
return base64EncodeUrlSafe(rleEncode(writer.buffer));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import * as types from "../tl/2_types.js";
|
|
2
|
-
export declare enum ChatPhotoType {
|
|
3
|
-
Chat = "chat",
|
|
4
|
-
User = "user"
|
|
5
|
-
}
|
|
6
2
|
export declare namespace ChatPhoto {
|
|
7
3
|
interface Base {
|
|
8
|
-
|
|
4
|
+
smallFileId: string;
|
|
5
|
+
smallFileUniqueId: string;
|
|
6
|
+
bigFileId: string;
|
|
7
|
+
bigFileUniqueId: string;
|
|
9
8
|
hasVideo: boolean;
|
|
10
|
-
photoId: bigint;
|
|
11
|
-
strippedThumb?: Uint8Array;
|
|
12
|
-
dcId: number;
|
|
13
9
|
}
|
|
14
10
|
interface User extends Base {
|
|
15
|
-
type: ChatPhotoType;
|
|
16
11
|
personal: boolean;
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
type: ChatPhotoType;
|
|
20
|
-
}
|
|
13
|
+
type Chat = Base;
|
|
21
14
|
}
|
|
22
15
|
export type ChatPhoto = ChatPhoto.User | ChatPhoto.Chat;
|
|
23
|
-
export declare function constructChatPhoto(photo: types.ChatPhoto): ChatPhoto.Chat;
|
|
24
|
-
export declare function constructChatPhoto(photo: types.UserProfilePhoto): ChatPhoto.User;
|
|
16
|
+
export declare function constructChatPhoto(photo: types.ChatPhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.Chat;
|
|
17
|
+
export declare function constructChatPhoto(photo: types.UserProfilePhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.User;
|
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
import * as types from "../tl/2_types.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./!0_file_id.js";
|
|
3
|
+
export function constructChatPhoto(photo, chatId, chatAccessHash) {
|
|
4
|
+
const smallFileId = new FileID(null, null, FileType.ChatPhoto, photo.dcId, {
|
|
5
|
+
mediaId: photo.photoId,
|
|
6
|
+
thumbnailSource: ThumbnailSource.ChatPhotoSmall,
|
|
7
|
+
chatId,
|
|
8
|
+
chatAccessHash,
|
|
9
|
+
accessHash: 0n,
|
|
10
|
+
volumeId: 0n,
|
|
11
|
+
localId: 0,
|
|
12
|
+
}).encode();
|
|
13
|
+
const smallFileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.photoId }).encode();
|
|
14
|
+
const bigFileId = new FileID(null, null, FileType.ChatPhoto, photo.dcId, {
|
|
15
|
+
mediaId: photo.photoId,
|
|
16
|
+
thumbnailSource: ThumbnailSource.ChatPhotoBig,
|
|
17
|
+
chatId,
|
|
18
|
+
chatAccessHash,
|
|
19
|
+
accessHash: 0n,
|
|
20
|
+
volumeId: 0n,
|
|
21
|
+
localId: 0,
|
|
22
|
+
}).encode();
|
|
23
|
+
const bigFileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.photoId }).encode();
|
|
9
24
|
if (photo instanceof types.ChatPhoto) {
|
|
10
25
|
return {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
smallFileId,
|
|
27
|
+
smallFileUniqueId,
|
|
28
|
+
bigFileId,
|
|
29
|
+
bigFileUniqueId,
|
|
30
|
+
hasVideo: photo.hasVideo || false,
|
|
16
31
|
};
|
|
17
32
|
}
|
|
18
33
|
else {
|
|
19
34
|
return {
|
|
20
|
-
type: ChatPhotoType.User,
|
|
21
35
|
personal: photo.personal || false,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
smallFileId,
|
|
37
|
+
smallFileUniqueId,
|
|
38
|
+
bigFileId,
|
|
39
|
+
bigFileUniqueId,
|
|
40
|
+
hasVideo: photo.hasVideo || false,
|
|
26
41
|
};
|
|
27
42
|
}
|
|
28
43
|
}
|